Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi Team,
I need to create a caalculated field using MAX & IF conditins if text is matching in a columns (Issue Type & Label) then add the text value for all the ID's in each row.
Logic:
IF "Issue Type"="Feature" & "Label" = "Pilot_Phd" THEN "Pilot"
EleseIF
IF "Issue Type"="Feature" & "Label" = "Testing" THEN "Test"
ElseIF
IF "Issue Type"="Feature" & "Label" = "Check" THEN "Control"
Else
"BAU" ENDIF
Please see the attached screenshot for expected "Output" in column "D".
I have tried below DAX, but it's not giving the result for all the rows.
Please giude me to resolve this issue.
DAX:
Output =
VAR MaxProject =
SWITCH(
TableName [Issue Type]="Feature" && TableName [Label]="Pilot_Phd", "Pilot",
TableName [Issue Type]="Feature" && TableName [Label]="Testing", "Test",
TableName[Issue Type]="Feature" && TableName [Label]="Check", "Control",
TRUE(),
RETURN
BLANK())
IF(TableName [ID]=TableName[ID], CALCULATE (MAXX (
FILTER (TableName, TableName [ID]=TableName[ID]), MaxProject)), "BAU")
Screenshot:
Solved! Go to Solution.
Hi @rkottap
Please try
Output =
VAR CurrentIDTable =
CALCULATETABLE ( TableName, ALLEXCEPT ( TableName, TableName[ID] ) )
VAR FeatureTypeRecord =
FILTER ( TableName, TableName[Issue Type] = "Feature" )
VAR FeatureLabel =
MAXX ( FeatureTypeRecord, TableName[Label] )
VAR Result =
SWITCH (
FeatureLable,
"Pilot_Phd", "Pilot",
"Testing", "Test",
"Check", "Control",
"BAU"
)
RETURN
Result
Hi @rkottap ,
Thanks to @tamerj1 for the reply, please allow me to provide another insight:
1. Create a calculated column.
Output =
VAR MaxProject = SWITCH(
TRUE(),
'Table'[Issue Type] = "Feature" && 'Table'[Label] = "Pilot_Phd", "Pilot",
'Table'[Issue Type] = "Feature" && 'Table'[Label] = "Testing", "Test",
'Table'[Issue Type] = "Feature" && 'Table'[Label] = "Check", "Control")
RETURN
MaxProject
2. Create the calculated column again to get the final result.
Column =
VAR _out = CALCULATE(MAX('Table'[Output]),FILTER(ALL('Table'),'Table'[ID] = EARLIER('Table'[ID])))
RETURN
IF(_out = BLANK(),"BAU",_out)
3. You can click the little eye next to the column name to hide unnecessary columns.
If your Current Period does not refer to this, please clarify in a follow-up reply.
Best Regards,
Clara Gong
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @rkottap
Please try
Output =
VAR CurrentIDTable =
CALCULATETABLE ( TableName, ALLEXCEPT ( TableName, TableName[ID] ) )
VAR FeatureTypeRecord =
FILTER ( TableName, TableName[Issue Type] = "Feature" )
VAR FeatureLabel =
MAXX ( FeatureTypeRecord, TableName[Label] )
VAR Result =
SWITCH (
FeatureLable,
"Pilot_Phd", "Pilot",
"Testing", "Test",
"Check", "Control",
"BAU"
)
RETURN
Result
I have added the VAR name in the second VAR line, where Table name is used;
Now it's working fine, Thank you for your help 🙂
Output =
VAR CurrentIDTable =
CALCULATETABLE ( TableName, ALLEXCEPT ( TableName, TableName[ID] ) )
VAR FeatureTypeRecord =
FILTER ( CurrentIDTable , TableName[Issue Type] = "Feature" )
VAR FeatureLabel =
MAXX ( FeatureTypeRecord, TableName[Label] )
VAR Result =
SWITCH (
FeatureLable,
"Pilot_Phd", "Pilot",
"Testing", "Test",
"Check", "Control",
"BAU"
)
RETURN
Result
Hi @tamerj1
Thank you for your response.
It's not returning the values as per the conditions.
It's adding text "BAU" for all the rows in table.
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
11 | |
9 | |
6 |