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

Join 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.

Reply
non23
Helper I
Helper I

Weekly Cost - Sum instead of result of DAX

We need help in computing the weekly cost of each fruit, but needs to recompute it if both fruits are harvested on the same day.
Sample April 15 (highlighted in yellow), Fruit 1 and Fruit 2 both have the same cost of 4600 for this day but have different weight.
1.png
We are able to compute the new cost however we want the total to be the sum of the new cost + existing cost not the output by the new cost as seen in the right most part of the photo.

Any tips on how to compute this please.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1745379753118.png

 

 

Jihwan_Kim_0-1745379697158.png

 

daily cost old: = 
SWITCH (
    TRUE (),
    HASONEVALUE ( fruit[fruit] ), SUMX ( VALUES ( 'calendar'[date] ), CALCULATE ( MAX ( data[cost] ) ) ),
    SUMX (
        VALUES ( 'calendar'[date] ),
        CALCULATE ( MAX ( data[cost] ), ALL ( fruit[fruit] ) )
    )
)

 

daily cost new (weighted cost): = 
SUMX (
    VALUES ( 'calendar'[date] ),
    SUMX (
        SUMMARIZE ( data, fruit[fruit] ),
        CALCULATE (
            DIVIDE (
                SUM ( data[weight] ),
                CALCULATE ( SUM ( data[weight] ), ALL ( fruit[fruit] ) )
            )
                * SUM ( data[cost] )
        )
    )
)

 

All cost: = 
[daily cost old:] + [daily cost new (weighted cost):]

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
v-kathullac
Community Support
Community Support

Thankyou @Jihwan_Kim for providing the solution.

 

Hi @non23 ,

we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?

If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

Regards,

Chaithanya.

v-kathullac
Community Support
Community Support

Thankyou @Jihwan_Kim for providing the solution.

 

Hi @non23 ,

we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?

If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

Regards,

Chaithanya.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1745379753118.png

 

 

Jihwan_Kim_0-1745379697158.png

 

daily cost old: = 
SWITCH (
    TRUE (),
    HASONEVALUE ( fruit[fruit] ), SUMX ( VALUES ( 'calendar'[date] ), CALCULATE ( MAX ( data[cost] ) ) ),
    SUMX (
        VALUES ( 'calendar'[date] ),
        CALCULATE ( MAX ( data[cost] ), ALL ( fruit[fruit] ) )
    )
)

 

daily cost new (weighted cost): = 
SUMX (
    VALUES ( 'calendar'[date] ),
    SUMX (
        SUMMARIZE ( data, fruit[fruit] ),
        CALCULATE (
            DIVIDE (
                SUM ( data[weight] ),
                CALCULATE ( SUM ( data[weight] ), ALL ( fruit[fruit] ) )
            )
                * SUM ( data[cost] )
        )
    )
)

 

All cost: = 
[daily cost old:] + [daily cost new (weighted cost):]

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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