Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
13 | |
8 | |
8 | |
7 |
User | Count |
---|---|
17 | |
13 | |
7 | |
6 | |
6 |