DAX Counting Groups of Repetition in Row - ssas

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]
)

Related

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.

MDX Calculation . Filetring a measure based on the value in another column

I see the problems I have are of nature 'filter one fact table measure based on the value of a column in the same fact table'.
I have a cube with measure called Report. ‘Calls’ and ‘Failure’ are columns of this measure. There is a dimension called ‘trial’. I have to write few new calculations in SSAS Cube.
Sum([measure].[calls] ) only if failure = 1 and value of [Trial categories].[Trail].&[1].
 I din’t get the desired result using filter. So I created a new column in the fact table ‘calls_if_failure’ = ‘calls’ or 0 depending on the value of failure column.
 And then in the calculated column I used sum([calls_if_failure], [Trial categories].[Trail].&[1]) . Is this the only way to do this?
Now I have many more requirements of the nature ->
Sum([measure].[calls] ) only if [measure].[visit] = 1
Should I take the same approach as before to arrive at the solution? If yes, then this would mean many more columns in fact table.
Appreciate any help. Thank You.
Struggling to understand the question a little but maybe the following will at least help to give you some ideas:
SUM (
IIF (
[Trial categories].CURRENTMEMBER IS [Trial categories].[Trail].&[1]
 , [measure].[calls]
 , NULL
)
)

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]
)

first 100 rows with DAX to retrieve Tabular Data

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!

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 ) )
)