Forum Discussion

francoisl's avatar
francoisl
Helper II
2 years ago
Solved

Conditional sums based on another measure

Hi all,    Here is the data.    I want to be able to compute a % of cost (cout) on sales (ventes) in two different ways: 1) within the Period (2023-P10) for exemple, straight out of the bo...
  • v-zhangti's avatar
    v-zhangti
    2 years ago

    Hi, francoisl 

     

    I've simply modelled some data to hopefully fit your situation.

    If [Sales], [Cost], and [%] are all measures, you can try the following.

    M1 = 
    Var _blankDate=CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),[Cost]=0))
    Return
    IF(HASONEVALUE('Table'[Date]),[Sales],SUMX(FILTER('Table',[Date]<>_blankDate),[Sales]))
    M2 = 
    Var _blankDate=CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),[Cost]=0))
    Return
    IF(HASONEVALUE('Table'[Date]),[Cost],SUMX(FILTER('Table',[Date]<>_blankDate),[Cost]))
    M% = 
    Var _blankDate=CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),[Cost]=0))
    Return
    IF(HASONEVALUE('Table'[Date]),[%],DIVIDE([M2],[M1]))

    Is this the result you expect? Please see the attached document.

     

    Best Regards,

    Community Support Team _Charlotte

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