Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hi all
I have a dataset (named IMP_UGE_DATA) with 2 relevant columns: IMP_UGE_DATA[FAILED] which is a text represent an error code and IMP_UGE_DATA[Total] which always have the value 1.
I create a measure that counts the number of rows with the most frequent FAILED :
maxFailureCount =
VAR CountByFailureCode =
GROUPBY (
IMP_UGE_DATA,
IMP_UGE_DATA[FAILED],
"countFail", SUMX ( CURRENTGROUP (), 'IMP_UGE_DATA'[Total] )
)
RETURN
MAXX ( CountByFailureCode, [countFail] )
Now I want to create a new measure that returns the most frequent FAILED.
I tried to use the CountByFailureCode since it supposes to return a table but I can not get the FAILED column.
how can I see the columns of the CountByFailureCode?
any suggestion how can I get the most frequent FAILED?
Thank you in advance for any help attempt.
Solved! Go to Solution.
Hi! Referencing columns in table variables is quite hard in DAX for some reason. But some iterator functions can do it. So if you don't want to use a calculated table for this, try someting like this:
MaxFailed =
VAR CountByFailureCode =
SUMMARIZE (
'IMP_UGE_DATA',
[FAILED],
"countFail", COUNTROWS ( 'IMP_UGE_DATA' )
)
VAR RankFailure =
ADDCOLUMNS (
CountByFailureCode,
"Rank", RANKX ( CountByFailureCode, [countFail] )
)
RETURN
CALCULATE ( MAXX ( FILTER ( RankFailure, [Rank] = 1 ), [FAILED] ) )
Perhaps you can create a calculated table like this:
FailCountTable =
VAR CountByFailureCode =
SUMMARIZE (
'IMP_UGE_DATA';
IMP_UGE_DATA[FAILED];
"countFail"; COUNTROWS ( 'IMP_UGE_DATA' )
)
RETURN
ADDCOLUMNS (
CountByFailureCode;
"Rank"; RANKX ( CountByFailureCode; [countFail];; DESC )
)
Then filter on Rank = 1 to get the top error code/codes.
I changed to SUMMARIZE and COUNTROWS instead of GROUPBY and SUMX. Then you don't need the Total column.
@Anonymous , @Greg_Deckler Thank you
I tried the following DAX:
Hi! Referencing columns in table variables is quite hard in DAX for some reason. But some iterator functions can do it. So if you don't want to use a calculated table for this, try someting like this:
MaxFailed =
VAR CountByFailureCode =
SUMMARIZE (
'IMP_UGE_DATA',
[FAILED],
"countFail", COUNTROWS ( 'IMP_UGE_DATA' )
)
VAR RankFailure =
ADDCOLUMNS (
CountByFailureCode,
"Rank", RANKX ( CountByFailureCode, [countFail] )
)
RETURN
CALCULATE ( MAXX ( FILTER ( RankFailure, [Rank] = 1 ), [FAILED] ) )
It does work.
I did not understand why we needed the maxx when we only have one filtered row.
Is it a workaround solution to return the column?
It's a workaround because the X funktions can access columns like that in variables. Also notice that if two or more codes have the same number of failures, the max (in alphabetical order) will be returned. MIN the other way around...
I don't know why it's not possible to write for example VALUES(Variable[Column]). Perhaps just not implemented yet in DAX.
Just create a table and return CountByFailureCode as the output. I think generally you would perhaps use ADDCOLUMNS to add a RANKX.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
87 | |
81 | |
53 | |
37 | |
35 |