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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

calculate sum by category and date

Hello,

I have a table and i want to create a mesure to calculate sum by each Cat, if i have the same Esp for each Cat and 2 dates i have to take only the mount of the lastdate

CatEspMountDate
A15405/01/2021
A15401/01/2021
A25401/01/2021
C3601/02/2021

 

The measure have to give me that :
For A = 54 (Esp=1 & Date=05/01/2021)+54 (Esp=2 & Date=01/01/2021)=>108

CatEspMountSum (Measure)Date
A15410805/01/2021
A15410801/01/2021
A25410801/01/2021
C36601/02/2021

 

 

Thank for your help!

2 REPLIES 2
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

Try the formula as below:

Col_result =
VAR count_ =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Cat] = EARLIER ( 'Table'[Cat] )
                && 'Table'[Esp] = EARLIER ( 'Table'[Esp] )
        )
    )
VAR count_cat =
    CALCULATE ( COUNTROWS ( 'Table' ), ALLEXCEPT ( 'Table', 'Table'[Cat] ) )
VAR a =
    IF (
        count_ = 2,
        CALCULATE (
            MAX ( 'Table'[Mount] ),
            FILTER ( ALL ( 'Table' ), LASTDATE ( 'Table'[Date] ) && count_ = 2 )
        ),
        'Table'[Mount]
    )
VAR b =
    IF ( count_cat = 1, 0, a )
RETURN
    a + b

vhenrykmstf_0-1645756225851.png

If the problem is still not resolved, please point it out. Looking forward to your reply.


Best Regards,
Henry


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

Anonymous
Not applicable

Thank you for your help but if i have a row for Cat =A and date =01/01/2022 and Esp = 20 the result become 128  and i want to get the result by year like for Cat = A  -> colResult =108 for Year =2021 and 20 for year =2022.
ColResult must to be calculated by year , how can i update the query ?

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.