first 100 rows with DAX to retrieve Tabular Data - powerpivot

HOw to retrieve FIRST (N) rows while retrieving a Table from Power Pivot with Dax?
What came to my mind is only to add an index column with Power Query and then to use FILTER() to enroll the SUMMARIZE()
My code:
EVALUATE
FILTER(
SUMMARIZE(
RTO_EnrolmentsAllCourses,
RTO_EnrolmentsAllCourses[CampusName],
RTO_EnrolmentsAllCourses[CoENo],
RTO_EnrolmentsAllCourses[Competency],
RTO_EnrolmentsAllCourses[Course_Finish],
RTO_EnrolmentsAllCourses[Course_start],
RTO_EnrolmentsAllCourses[CourseAttempt],
RTO_EnrolmentsAllCourses[CourseID],
RTO_EnrolmentsAllCourses[CourseName],
RTO_EnrolmentsAllCourses[Index]
),
RTO_EnrolmentsAllCourses[Index]<50)
Thanks in advance

Try this:
EVALUATE(
SAMPLE(
50,
RTO_EnrolmentsAllCourses,
RTO_EnrolmentsAllCourses[CampusName], 1,
RTO_EnrolmentsAllCourses[CoENo], 1
)
)
That returns the first 50 rows ordered by CampusName ascending (that's the value 1 right after CampusName) and CoENo ascending. You have to provide order by columns of you want a predictable 50 rows rather than a random 50 rows per the documentation.

Thanks, GregGalloway! It is working just fine. Enrolling SAMPLE () into SUMMARIZE() I just retrieve what I needed.
EVALUATE
SUMMARIZE(
SAMPLE(
10,
RTO_EnrolmentsAllCourses,
RTO_EnrolmentsAllCourses[CampusName], 1
),
RTO_EnrolmentsAllCourses[AgentName],
RTO_EnrolmentsAllCourses[CampusName]
)
Thanks again!

Related

DAX Counting Groups of Repetition in Row

Not long into my DAX understanding and i've hit a brickwall.
I need to create a measure that counts if a RANDOM_PERSON_ID is repeated 5 times.
So, my measure value with the test dataset should be 1 (9662AF155704B3F7).
Any help greatly appreciated.
Thanks
Danny
Thanks to Amitchandac # community.powerbi.com for giving me the answer.
COUNTAX (
FILTER (
SUMMARIZE (
Table,
Table[RANDOM_PERSON_ID],
"EqualTo5", COUNTA ( Table[RANDOM_PERSON_ID] )
),
[EqualTo5] = 5
),
Table[RANDOM_PERSON_ID]
)

custom count measure runs forever MDX

So this question goes off the one here
I've been trying to do a similar count measure and I did the suggested solution but it's still running.... and it's been more than 30 minutes with no results, while without that it runs in under a minute. So am I missing something? Any guidance would help. Here is my query:
WITH
MEMBER [Measures].[IteractionCount] AS
NONEMPTY
(
FILTER
(
([DimInteraction].[InteractionId].[ALL].Children,
[Measures].[Impression Count]),
[DimInteraction].[Interaction State].&[Enabled]
)
).count
SELECT
(
{[Measures].[IteractionCount],
[Measures].[Impression Count]}
)
ON COLUMNS,
(
([DimCampaign].[CampaignId].[CampaignId].MEMBERS,
[DimCampaign].[Campaign Name].[Campaign Name].MEMBERS,
[DimCampaign].[Owner].[Owner].MEMBERS)
,[DimDate].[date].[date].MEMBERS
)
ON ROWS
FROM
(
SELECT
(
{[DimDate].[date].&[2020-05-06T00:00:00] : [DimDate].[date].&[2020-05-27T00:00:00]}
)
ON COLUMNS
FROM [Model]
)
WHERE
(
{[DimCampaign].[EndDate].&[2020-05-27T00:00:00]:NULL},
[DimCampaign].[Campaign State].&[Active],
{[DimInteraction].[End Date].&[2020-05-27T00:00:00]:NULL}//,
//[DimInteraction].[Interaction State].&[Enabled]
)
I don't know if FILTER is affecting it in any way but I tried it with and without and it still runs forever. I do need it specifically filtered to [DimInteraction].[Interaction State].&[Enabled]. I have also tried to instead filter to that option in the WHERE clause but no luck
Any suggestions to optimize this would be greatly appreciated! thanks!
UPDATE:
I end up using this query to load data into a python dataframe. Here is my code for that. I used this script for connecting and loading the data. I had to make some edits to it though to use windows authentication.
ssas_api._load_assemblies() #this uses Windows Authentication
conn = ssas_api.set_conn_string(server='server name',db_name='db name')
df = ssas_api.get_DAX(connection_string=conn, dax_string=query))
The dax_string parameter is what accepts the dax or mdx query to pull from the cube.
Please try this optimization:
WITH
MEMBER [Measures].[IteractionCount] AS
SUM
(
[DimInteraction].[InteractionId].[InteractionId].Members
* [DimInteraction].[Interaction State].&[Enabled],
IIF(
IsEmpty([Measures].[Impression Count]),
Null,
1
)
)
SELECT
(
{[Measures].[IteractionCount],
[Measures].[Impression Count]}
)
ON COLUMNS,
(
([DimCampaign].[CampaignId].[CampaignId].MEMBERS,
[DimCampaign].[Campaign Name].[Campaign Name].MEMBERS,
[DimCampaign].[Owner].[Owner].MEMBERS)
,[DimDate].[date].[date].MEMBERS
)
PROPERTIES MEMBER_CAPTION
ON ROWS
FROM
(
SELECT
(
{[DimDate].[date].&[2020-05-06T00:00:00] : [DimDate].[date].&[2020-05-27T00:00:00]}
)
ON COLUMNS
FROM [Model]
)
WHERE
(
{[DimCampaign].[EndDate].&[2020-05-27T00:00:00]:NULL},
[DimCampaign].[Campaign State].&[Active],
{[DimInteraction].[End Date].&[2020-05-27T00:00:00]:NULL}//,
//[DimInteraction].[Interaction State].&[Enabled]
)
CELL PROPERTIES VALUE
If that doesn’t perform well the please describe the number of rows returned by your query when you comment out IteractionCount (sic) from the columns axis. And please describe how many unique InteractionId values you have.

Is there a dax Function that support paging in query?

I wrote a DAX query that include some different kind of measure in SSAS Tabular model. Now I have to break my solution in some pages for using in application and sort by my measures.
I used TOPNSKIP() function but can not creating table that sorted by measure.
DAX code:
EVALUATE
SELECTCOLUMNS(
TopnSkip ( 5,0,'Station',Station[StationTitle],asc),
"NameOfStation",Station[StationTitle],
"TradeSellPrice", [TradeSellPrice],
"TradePrice" ,[TradePrice],
BrokerCommission",[BrokerCommission])
Order by [TradePrice] asc
This code first select Top 5 from "Station" table and then sorted by "Tradeprice". This is not my expectation and what I need a solution sorted by "TradePrice".
EVALUATE
TOPNSKIP (
5, 0,
SELECTCOLUMNS (
'Station',
"NameOfStation", 'Station'[StationTitle],
"TradeSellPrice", [TradeSellPrice],
"TradePrice", [TradePrice],
"BrokerCommission", [BrokerCommission]
),
[TradePrice],
ASC
)
ORDER BY [TradePrice] ASC
First arg to SELECTCOLUMNS is a table. You passed it the table TOPNSKIP ( 5, 0, 'Station', 'Station'[StationTitle], ASC ), which is the 5-row table of the first five StationTitles.
Then, you defined the columns to select from that 5-row table. And finally you ordered the output of that table by [TradePrice].
TOPNSKIP takes a table as input. So pass it the table with the columns you need to define, and sort by any of them.

Issue with Summarize in SSAS 2014 data model

Good Day all.
I really hope someone can assist with this. The following code works great in DaxStudio and returns a topn table.
evaluate
TOPN(10,SUMMARIZE(factDailyPlay,factDailyPlay[PlayerAccountNumber],"Top10",SUM(factDailyPlay[ActualWin])),[Top10],0)
What I am trying to return in my model though is sum of those top 10 values as a single scalar value of that topn table.
I keep getting the following error.
The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
Thanks
Try using:
EVALUATE
ROW (
"Total", SUMX (
TOPN (
10,
SUMMARIZE (
factDailyPlay,
factDailyPlay[PlayerAccountNumber],
"Top10", SUM ( factDailyPlay[ActualWin] )
),
[Top10], 0
),
[Top10]
)
)
Basically the below expression calculates the sum you require.
SUMX (
TOPN (
10,
SUMMARIZE (
factDailyPlay,
factDailyPlay[PlayerAccountNumber],
"Top10", SUM ( factDailyPlay[ActualWin] )
),
[Top10], 0
),
[Top10]
)

DAX formula for - MAX of COUNT

I have the below dataset:
using the measure:
BalanceCount := COUNT(Balances[Balance])
which gives me the result:
However, I want the Grand Total to show the maximum amount of the BalanceCount, which is 2.
NewMeasure:=
MAXX(
SUMMARIZE(
FactTable
,FactTable[Account]
,FactTable[MonthEnd]
)
,[BalanceCount]
)
SUMMARIZE() groups by the columns specified, and MAXX() iterates through the table specified, returning the maximum of the expression in the second argument evaluated for each row in its input table.
Since the filter context will limit the rows of the fact table, we'll only have the appropriate subsets in each column/row grand total.
I found a solution that works for this particular case. It will not work if columns other than Account and MonthEnd are included in the filter context.
MaxBalanceCount:=
MAXX ( SUMMARIZE (
Balances,
Balances[Account],
Balances[MonthEnd]
),
CALCULATE ( COUNTROWS ( Balances ) )
)