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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AdityaNayak
Frequent Visitor

DAX formula for share and contribution calculations

Hello Power BI Community,

 

Happy New Year! 😊 I require help with DAX calculations in Power BI. Please refer the below image. Columns A, B, and C are from the raw data. I require metrics to be calculated as mentioned in columns "D" and "E" with the corresponding expected values in columns "F" and "G", respectively. Please help!

Help.PNG

 

Thanks in advance,
Aditya Nayak

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

Hi  @AdityaNayak ,

Here are the steps you can follow:

1. In Power query, Add Column – Index Column From 1.

vyangliumsft_0-1641456980099.png

2. Create calculated column.

Mod = MOD('SumTable'[Index],2)
Share expected value =
var _sum1=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])))
var _sum2=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])-1))
return
IF(
    'SumTable'[Mod]=1,BLANK(),DIVIDE(_sum1,_sum2)
)
Contribution expected value =
var _sum1=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])))
var _min=MINX(FILTER(ALL(SumTable),'SumTable'[Geography]=EARLIER('SumTable'[Geography])),[Index])
var _sum2=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=_min))
var _sum3=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])-1))
return
IF(
    'SumTable'[Mod]=1,DIVIDE(_sum1,_sum2),DIVIDE(_sum1,_sum3)
)

3. Result:

vyangliumsft_1-1641456980108.png

 

Best Regards,

Liu Yang

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

6 REPLIES 6
v-yangliu-msft
Community Support
Community Support

Hi  @AdityaNayak ,

You can change [Contribution expected value] to this:

Contribution expected value =
var _sum1=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])))
var _min=MINX(FILTER(ALL(SumTable),'SumTable'[Geography]=EARLIER('SumTable'[Geography])),[Index])
var _sum2=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=_min))
var _sum3=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])-1))
return
IF(
    'SumTable'[Mod]=1,DIVIDE(_sum1,_sum2),BLANK()
)

vyangliumsft_0-1641535391175.png

Or this form:

Contribution expected value =
var _sum1=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])))
var _min=MINX(FILTER(ALL(SumTable),'SumTable'[Geography]=EARLIER('SumTable'[Geography])),[Index])
var _sum2=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=_min))
var _sum3=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])-1))
return
IF(
    'SumTable'[Mod]=1,BLANK(),DIVIDE(_sum1,_sum3)
)

vyangliumsft_1-1641535391179.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Hi @v-yangliu-msft ,

 

Spot on! This is exactly what I require. Thanks a lot! 😊

 

Regards,

Aditya

v-yangliu-msft
Community Support
Community Support

Hi  @AdityaNayak ,

Here are the steps you can follow:

1. In Power query, Add Column – Index Column From 1.

vyangliumsft_0-1641456980099.png

2. Create calculated column.

Mod = MOD('SumTable'[Index],2)
Share expected value =
var _sum1=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])))
var _sum2=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])-1))
return
IF(
    'SumTable'[Mod]=1,BLANK(),DIVIDE(_sum1,_sum2)
)
Contribution expected value =
var _sum1=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])))
var _min=MINX(FILTER(ALL(SumTable),'SumTable'[Geography]=EARLIER('SumTable'[Geography])),[Index])
var _sum2=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=_min))
var _sum3=CALCULATE(SUM('SumTable'[Sales]),FILTER(ALL('SumTable'),'SumTable'[Geography]=EARLIER('SumTable'[Geography])&&'SumTable'[Index]=EARLIER('SumTable'[Index])-1))
return
IF(
    'SumTable'[Mod]=1,DIVIDE(_sum1,_sum2),DIVIDE(_sum1,_sum3)
)

3. Result:

vyangliumsft_1-1641456980108.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Hi @v-yangliu-msft ,

 

Thanks a lot for this solution! 🙂 It works perfectly for "Share expected value".

 

One minor change that came up just now, though. I want the corresponding rows of "Contribution expected value" to be blank, as those for "Share expected value".

 

Regards,

Aditya Nayak

amitchandak
Super User
Super User

@AdityaNayak , need to understand data model and raw data

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

GeographyProductSalesShare formulaContribution formulaShare expected valueContribution expected value
GlobalTotal Furniture1000 -Total Furniture/Total Furniture -100%
GlobalManufacturer Furniture600Manufacturer Furniture/Total FurnitureManufacturer Furniture/Total Furniture60%60%
GlobalSub-Category Chairs900 -Sub-Category Chairs/Total Furniture -90%
GlobalManufacturer Chairs400Manufacturer Chairs/Sub-Category ChairsManufacturer Chairs/Sub-Category Chairs44%44%
GlobalSub-Category Tables700 -Sub-Category Tables/Total Furniture -70%
GlobalManufacturer Tables500Manufacturer Tables/Sub-Category TablesManufacturer Tables/Sub-Category Tables71%71%
IndiaTotal Furniture100 -Total Furniture/Total Furniture -100%
IndiaManufacturer Furniture80Manufacturer Furniture/Total FurnitureManufacturer Furniture/Total Furniture80%80%
IndiaSub-Category Chairs90 -Sub-Category Chairs/Total Furniture -90%
IndiaManufacturer Chairs70Manufacturer Chairs/Sub-Category ChairsManufacturer Chairs/Sub-Category Chairs78%78%
IndiaSub-Category Tables50 -Sub-Category Tables/Total Furniture -50%
IndiaManufacturer Tables40Manufacturer Tables/Sub-Category TablesManufacturer Tables/Sub-Category Tables80%80%

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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