Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
Check it out now!Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
I am trying to build a dashboard and need to subtract two specific row values from another row. For example deduct the headcount of two other leaders (say A2 and A3) from another higher level leader (say A1). I need all other rows (including the rows for leaders A2 and A3) to simply return the same value. Also, I am looking for a Power Query solution if possible.
Below is the Power Query formula that I am using. This works well as long as I only have one set of data with a particular date associated with it. If there is a different set of data with a different date associated with it, it does not work correctly. Is there a way to re-write this to include the logic " For this date, Final Headcount A1 = A1-A2-A3"?
= Table.AddColumn(#"Trimmed Text", "Final Headcount A1", each if [Leader Name]="A1" then [Headcounts]
-Table.SelectRows(#"Trimmed Text",each [Leader Name]="A2"){0}[Headcounts]
-Table.SelectRows(#"Trimmed Text",each [Leader Name]="A3"){0}[Headcounts]
else [Headcounts])
Here are the current and result tables.
Solved! Go to Solution.
Hi @Sriu2022 ,
Try the below modification to the provided code.
Table.AddColumn(#"Trimmed Text", "Final Headcount A1", each if [Leader Name]="A1" then [Headcounts]
-Table.SelectRows(#"Trimmed Text",(x)=> x[Leader Name]="A2" and x[Date]=[Date]){0}[Headcounts]
-Table.SelectRows(#"Trimmed Text",(x)=> x[Leader Name]="A3" and x[Date]=[Date]){0}[Headcounts]
else [Headcounts])
Regards
KT
Hi @Sriu2022 ,
Try the below modification to the provided code.
Table.AddColumn(#"Trimmed Text", "Final Headcount A1", each if [Leader Name]="A1" then [Headcounts]
-Table.SelectRows(#"Trimmed Text",(x)=> x[Leader Name]="A2" and x[Date]=[Date]){0}[Headcounts]
-Table.SelectRows(#"Trimmed Text",(x)=> x[Leader Name]="A3" and x[Date]=[Date]){0}[Headcounts]
else [Headcounts])
Regards
KT
I am getting the below error with this code.
Expression.Error: A cyclic reference was encountered during evaluation.
First, you will need to create a column indicating the group name. For example the A group might be A1, A2, A3, while the B group might just be B. To do this just use Extract menu option in the transform ribbon.
Next, do a groupby operation with Date and the new group column you created. Use 2 aggregations:
1. The Max of HeadCount
2. The Sum of HeadCount
Next, subtract the max headcount from the sum headcount, removing the max headcount from the sum headcount calculation.
Finally, subtract sum headcount from the max head count.