Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Create a column with the sum of all rows

Good morning, 

 

I am trying to create 3 calculated columns that show in every row the total sum of specific rows in the same table, at the same time, avoid circular dependencies, and be responsive to slicers that will appear in the dashboard.

 

I have tried (calculate,all) and (calculate,allexcept) and I don't get the result I'm looking for. Please see the example below:

 

STATEIDUNITSTYPETOTAL UNITSTOTAL UNITS PER IDTOTAL UNITS (CAR+VAN) PER ID
FLORIDA12341,000CAR5,1052,7001,900
FLORIDA1234900VAN5,1052,7001,900
FLORIDA1234800SUV5,1052,7001,900
FLORIDA4573760BIKE5,1051,650890
FLORIDA4573890CAR5,1051,650890
FLORIDA4578755VAN5,105755755


Ultimately I will build a flag that compares the last two columns and show a 1 or 0 depending on the "type", but I really need to show this table (from excel) as a visualization in the dashboard, is it possible?

 

Thank you for your support.

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could create it by following:

Column = CALCULATE(SUM([UNITS]),FILTER(ALLEXCEPT('Table','Table'[ID]),[TYPE] in {"VAN","CAR"}))
Column 2 = CALCULATE(SUM([UNITS]),ALL('Table'))
Column 3 = CALCULATE(SUM([UNITS]),ALLEXCEPT('Table','Table'[ID]))

The final output is shown below:

vyalanwumsft_0-1634015186432.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could create a column or measure as follows:

1.create a column.

totalPROJECTED = CALCULATE(SUM([PROJECTED]),ALLEXCEPT('Table','Table'[ID]))
flag1 = IF([totalPROJECTED]>[totalunit],1,0)

then put it into table and don't summarize.

vyalanwumsft_0-1634262569574.png

2.you also could use measure .

flag2 = 
var _cout=CALCULATE(DISTINCTCOUNT([ID]),FILTER('Table',[totalPROJECTED]>[totalunit]))
return IF(_cout=BLANK(),0,_cout)

The final output is shown below:

vyalanwumsft_1-1634262629186.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Good morning,

 

Flag 2 worked partially, now I have 3 questions:

 

1) In some cases where units = projected on an ID I am getting a 1, not a zero, which I think is because at least one type of vehicle in the same ID had units < projected, although the overall sum is equal, do you know what could be happening?

2) How do I make "flag 2" not responsive only to a STATE slicer that will be in the dashboard?

v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could create it by following:

Column = CALCULATE(SUM([UNITS]),FILTER(ALLEXCEPT('Table','Table'[ID]),[TYPE] in {"VAN","CAR"}))
Column 2 = CALCULATE(SUM([UNITS]),ALL('Table'))
Column 3 = CALCULATE(SUM([UNITS]),ALLEXCEPT('Table','Table'[ID]))

The final output is shown below:

vyalanwumsft_0-1634015186432.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hello, thank you for answer, it worked perfectly, however, now I have another issue.

 

I want to create a calculated column as a "Flag" with just 0's and 1's if the units where less than projected. When doing so, I get the addition of all rows where the condition was met, not just using the overall totals, how can I do that?

 

This is my database:

 

STATEIDTYPEUNITSPROJECTED
FLORIDA1234CAR10001050
FLORIDA1234VAN900910
FLORIDA1234SUV800840
FLORIDA4573BIKE760800
FLORIDA4573CAR890900
FLORIDA4578VAN755700

 

This is my formula for the flag column:

FLAG = IF (UNITS < PROJECTED, 1, 0)

 

And this is what I am getting:

 

STATEIDUNITSPROJECTEDCURRENT FLAGEXPECTED FLAG
FLORIDA12342700280031
FLORIDA45731650170021
FLORIDA457875570000

 

I understand why the current flag returns those numbers (it is adding the total times the condition was met by "type" and "ID", but I need that flag to be the EXPECTED FLAG column, with just 0's and 1's.

 

Please note that the TYPE column will be a slicer in the dashboard, not included in the table, so I need the final table to show if the overall ID units (depending on option(s) selected) where less than projections.

 

 

 

Can you help me with that?

 

I will mark the answer as Solution, but I don't want to create another post, unless that's what's required.

 

Thank you for your support.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors