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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
socksinbox
Helper I
Helper I

Calculating difference between consecutive rows

How to calculate difference between count of Active & Negative Ppl for each segment in DAX

e.g.

in below table Blank segment has 3 active & 6 negative so the diff is -3

so the final table should look this

Segment | difference
Blank | -3

etc

 

PeopleTypeSegment
ActiveBLANK
ActiveBLANK
ActiveBLANK
NegativeBLANK
NegativeBLANK
NegativeBLANK
NegativeBLANK
NegativeBLANK
NegativeBLANK
PassiveBLANK
PassiveBLANK
ActiveEC
ActiveEC
PassiveEC
ActiveResident
ActiveResident
ActiveResident
NegativeResident
NegativeResident
PassiveResident
ActiveSME
ActiveSME
NegativeSME
NegativeSME
PassiveSME

 

 

 

3 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @socksinbox ,

 

It can be segment wise, you just create a table and drag the segment column into it,

then create the measue I did, then drag to it, you will see the result.

 

Or do you mean you want to use a DAX to create a new table with segment column and diff column?

 

Aiolos Zhao

View solution in original post

Anonymous
Not applicable

Hi @socksinbox ,

 

If you want to create a new table, please use below expression :

Table = SUMMARIZE(Table4,Table4[Segment],"Diff",CALCULATE(COUNTROWS(Table4),Table4[PeopleType] = "Active") - CALCULATE(COUNTROWS(Table4),Table4[PeopleType] = "Negative"))

Thanks.

Aiolos Zhao

View solution in original post

Hi,

Based on the data that you have shared, the average should be 0.  Try this measure

Measure = AVERAGEX(SUMMARIZE(CALCULATETABLE(Data,Data[PeopleType]="Active"||Data[PeopleType]="Negative"),Data[Segment],"Active",CALCULATE(COUNTROWS(Data),Data[PeopleType]="Active"),"Negative",CALCULATE(COUNTROWS(Data),Data[PeopleType]="Negative")),[Active]-[Negative])

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

10 REPLIES 10
Anonymous
Not applicable

Hi @socksinbox ,

 

Please try to use below measure, it works in my demo :

CALCULATE(COUNTROWS(Table4),Table4[PeopleType] = "Active") - CALCULATE(COUNTROWS(Table4),Table4[PeopleType] = "Negative")

Thanks.

Aiolos Zhao

 

Thanks @Anonymous for this.

 

Actually this will calculate the overall difference, however, I would like to have segment wise difference. So I would need to return a table not a measure

 

thanks

 

Anonymous
Not applicable

Hi @socksinbox ,

 

It can be segment wise, you just create a table and drag the segment column into it,

then create the measue I did, then drag to it, you will see the result.

 

Or do you mean you want to use a DAX to create a new table with segment column and diff column?

 

Aiolos Zhao

Yes.. I mean I would like to create a new data table.
Actually, once I will have the segment-wise difference then I will create a measure on the top of that which will take the average of all differences and show in a card visual

 

cheers

Hi,

Based on the data that you have shared, the average should be 0.  Try this measure

Measure = AVERAGEX(SUMMARIZE(CALCULATETABLE(Data,Data[PeopleType]="Active"||Data[PeopleType]="Negative"),Data[Segment],"Active",CALCULATE(COUNTROWS(Data),Data[PeopleType]="Active"),"Negative",CALCULATE(COUNTROWS(Data),Data[PeopleType]="Negative")),[Active]-[Negative])

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks @Ashish_Mathur  for your help

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @socksinbox ,

 

If you want to create a new table, please use below expression :

Table = SUMMARIZE(Table4,Table4[Segment],"Diff",CALCULATE(COUNTROWS(Table4),Table4[PeopleType] = "Active") - CALCULATE(COUNTROWS(Table4),Table4[PeopleType] = "Negative"))

Thanks.

Aiolos Zhao

Thanks @Anonymous  for your help

Anonymous
Not applicable

Glad to help you ~

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.