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

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

Reply
Saideep16
New Member

Calculate Percentage difference between two columns and grouping on state

Hi Everyone,

 

Thanks in advance for all who tried to help me!!

 

I am looking for a measure to calculate percentage difference between two columns (Prev cnt, Curr cnt).

 

FYI, currently my measure calculating percentage difference 100% for overall count for all states or stateid.

DIVIDE ( [prev cnt], [curr cnt] )

But I need percentage as below:

example:

For state 'GA' and Stateid  there are four records you see below, I need to calculate 100% for those four records (GA: 4 records by 100%) 

Then next state 'CA' which has three records for that next 100% has to divide for those three records. 

Same goes for next states.

 

I need DAX to calculate 'previous cnt' and 'current cnt' column percentage difference individually for each state.

 

Saideep16_0-1672155798794.png

 

 

Thanks,

 

1 ACCEPTED SOLUTION
sevenhills
Super User
Super User

The output you are expecting for each row is not clear. Also, you did not mention whether DIFF CNT is a measure or a column!.

 

Assuming, DIFF CNT is a column, let us say the TableState data is below:

sevenhills_0-1672184223681.png

 

Percentage measure:

 

PERCENTAGE = 
VAR _currState = SELECTEDVALUE(TableState[STATE])
var _prev = sumx(TableState, TableState[PREV CNT])
var _curr = sumx(TableState, TableState[CURR CNT])
var _curr1 = CALCULATE( sum(TableState[CURR CNT]), FILTER(all(TableState), TableState[STATE] = _currState))
var _prev1 = CALCULATE( sum(TableState[PREV CNT]), FILTER(all(TableState), TableState[STATE] = _currState))

return if (HASONEFILTER(TableState[STATE]), (_prev / _curr1) ,  (_prev / _curr ) )

 

 

 Output:

sevenhills_1-1672184297788.png

 

Adjust the formula to your needs!

View solution in original post

4 REPLIES 4
sevenhills
Super User
Super User

The output you are expecting for each row is not clear. Also, you did not mention whether DIFF CNT is a measure or a column!.

 

Assuming, DIFF CNT is a column, let us say the TableState data is below:

sevenhills_0-1672184223681.png

 

Percentage measure:

 

PERCENTAGE = 
VAR _currState = SELECTEDVALUE(TableState[STATE])
var _prev = sumx(TableState, TableState[PREV CNT])
var _curr = sumx(TableState, TableState[CURR CNT])
var _curr1 = CALCULATE( sum(TableState[CURR CNT]), FILTER(all(TableState), TableState[STATE] = _currState))
var _prev1 = CALCULATE( sum(TableState[PREV CNT]), FILTER(all(TableState), TableState[STATE] = _currState))

return if (HASONEFILTER(TableState[STATE]), (_prev / _curr1) ,  (_prev / _curr ) )

 

 

 Output:

sevenhills_1-1672184297788.png

 

Adjust the formula to your needs!

tamerj1
Super User
Super User

Hi @Saideep16 

please try

PERCENTAGE =
DIVIDE (
'Table'[DIFF CNT],
CALCULATE ( SUM ( 'Table'[DIFF CNT] ), ALLEXCEPT ( 'Table', 'Table'[STATE] ) )
)

FreemanZ
Super User
Super User

hi @Saideep16 

The description is not that clear. It would save a lot of effort if you could:

1) fill out the expected result column

2) indicate which headers are column and which are measures. 

amitchandak
Super User
Super User

@Saideep16 , refer if offset can help

Power BI Offset Compare Categories, Time Intelligence MOM, QOQ, and YOY: https://youtu.be/5YMlkDNGr0U

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.