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
mvrali
Frequent Visitor

Need help with DAX cumulative conditional aggregation

I am working on creating injury logs. Here is the sample data:

 

CaseTypeStart DateDays
XLD9/1/2017100
XLD12/1/201720
XLT10/1/201740
XLT11/1/201780
YLT10/1/201750
YLT9/1/201750
YLD10/1/201770
YLD11/1/201790
YLT12/1/201730

 

 

I need to aggregate the total periods for Cases X and Y based on the Type (LD or LT). The rules are:

  • Total of LD and LT capped at 180
  • Do the calcualtion until reaching 180 total  based on the date (include the ones that have earlier dates and their sum is less than 180)
  • if reaching the cap in the middle of a period (Yellow colors) then just use part of it until reaching 180.
  • Green means the ones that should be used, Yellow partially used to reach the cap, and red means it was not used.

Here is the results I am looking for:

 

 LDLT
X12060
Y50130

 

I appreciate your help!

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

Hi @mvrali,

 

It seems like you need to calculate based on specific sort order, I think you need to add index column to calculate loop table.

 

Steps:

1. Enter into query editor and add index column.

2. Add calculated column to change days based on rolling target.

Spoiler
Filtered Days =
VAR _previous =
    SUMX (
        FILTER (
            Test,
            [Case] = EARLIER ( Test[Case] )
                && [Index] < EARLIER ( Test[Index] )
        ),
        [Days]
    )
VAR _current =
    SUMX (
        FILTER (
            Test,
            [Case] = EARLIER ( Test[Case] )
                && [Index] <= EARLIER ( Test[Index] )
        ),
        [Days]
    )
RETURN
    IF (
        _current <= 180,
        [Days],
        IF ( _previous < 180 && _current > 180, 180 - _previous, 0 )
    )

3. Create matrix visual with above columns.

2.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @mvrali,

 

It seems like you need to calculate based on specific sort order, I think you need to add index column to calculate loop table.

 

Steps:

1. Enter into query editor and add index column.

2. Add calculated column to change days based on rolling target.

Spoiler
Filtered Days =
VAR _previous =
    SUMX (
        FILTER (
            Test,
            [Case] = EARLIER ( Test[Case] )
                && [Index] < EARLIER ( Test[Index] )
        ),
        [Days]
    )
VAR _current =
    SUMX (
        FILTER (
            Test,
            [Case] = EARLIER ( Test[Case] )
                && [Index] <= EARLIER ( Test[Index] )
        ),
        [Days]
    )
RETURN
    IF (
        _current <= 180,
        [Days],
        IF ( _previous < 180 && _current > 180, 180 - _previous, 0 )
    )

3. Create matrix visual with above columns.

2.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft,

 

Worked great! Thanks for the soloution. 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.