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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Sum of expense is wrong when multiple date selected

this is my pbix file : https://1drv.ms/u/s!Ag9tIyk2ofNRjk7ex9NVCSWmzVF9?e=hzuIkt


i have this measure:

 

Expenses = 
var NEWtotalrevenue = CALCULATE(SUM(Revenue[Total]),FILTER('Calendar','Calendar'[Date] >= DATE(2022,10,3)))
VAR OLDtotalrevenue = CALCULATE(SUMX(Revenue,Revenue[Amount]*Revenue[Qtty]),FILTER('Calendar','Calendar'[Date] < DATE(2022,10,3)))
VAR totalrevenue = OLDtotalrevenue + NEWtotalrevenue
Var newsalesmanrevenue = CALCULATE(SUM(Revenue[Total]),FILTER('Calendar','Calendar'[Date] >= DATE(2022,10,3)),Revenue[Salesman]="A")
VAR Oldsalesmanrevenue = CALCULATE(SUMX(Revenue,Revenue[Amount]*Revenue[Qtty]),FILTER('Calendar','Calendar'[Date] < DATE(2022,10,3)),Revenue[Salesman]="A")
VAR salesmanrevenue = Oldsalesmanrevenue + newsalesmanrevenue
VAR percentage = salesmanrevenue/totalrevenue
var expenses = SUM(Expense[Total])
return
expenses*percentage

 




those are the pictures:
expense table:

expense table.png

 

revenue table:

Screenshot 2022-10-14 153511.png

 

week 40  :

week40.png


 week 41:

week41.png

both selected weeks:

both weeks.png

as you see expense on both selected dates is 801.01 
but if you manually add week 40 and week 41,
i get 365.30 + 431.27 = 796.57 
any help is appreciated

@Jihwan_Kim 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood the question correctly, but please try the below measure whether it suits your requirement.

 

Expenses V2 =
VAR _newtable =
    ADDCOLUMNS (
        DISTINCT ( 'Calendar'[Week of Year] ),
        "@percentage", [Percentage V2],
        "@expensetotal", CALCULATE ( SUM ( Expense[Total] ) )
    )
RETURN
    SUMX ( _newtable, [@percentage] * [@expensetotal] )

 

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood the question correctly, but please try the below measure whether it suits your requirement.

 

Expenses V2 =
VAR _newtable =
    ADDCOLUMNS (
        DISTINCT ( 'Calendar'[Week of Year] ),
        "@percentage", [Percentage V2],
        "@expensetotal", CALCULATE ( SUM ( Expense[Total] ) )
    )
RETURN
    SUMX ( _newtable, [@percentage] * [@expensetotal] )

 

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Anonymous
Not applicable

Youre a life saver thank you

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.