Forum Discussion

Srijit's avatar
Srijit
Regular Visitor
4 years ago
Solved

Need help on DAX

Need help on the below scenario

 

I have data for Year ,QTR,Mon,Week but the data(Total Count from Start) what we see is an accumiliated value. For Eg 2390 for Project 1 is not the count for that week alone, its from the start. My Requirement is as below 

 

1. Get the count value for Month (eg if OCT is selected in slicer them subtract the max of Nov with MAX of Oct)

2.Same way for QTR and Year

3.Finally when I select a Project and a month/QTR/Yr I should see value for the selected Project for the Month/QTR/Yr selected.

 

Tried to find out in google but couldnt get much help. PLease help on this issue

Project NameYearQTRMonth NameWeekTotal Count from start
Project 12021Q2Oct32390
Project 22021Q2Oct31390
Project 32021Q2Oct3890
Project 12021Q2Oct42400
Project 22021Q2Oct41400
Project 32021Q2Oct4900
Project 12021Q2Nov32410
Project 22021Q2Nov31410
Project 32021Q2Nov3910
Project 12021Q2Nov42430
Project 22021Q2Nov41440
Project 32021Q2Nov4950
Project 12021Q2Dec32470
Project 22021Q2Dec31450
Project 32021Q2Dec3970
Project 12021Q2Dec42475
Project 22021Q2Dec41455
Project 32021Q2Dec4975
Project 12022Q3Jan32480
Project 22022Q3Jan31475
Project 32022Q3Jan3988
Project 12022Q3Jan42495
Project 22022Q3Jan41490
Project 32022Q3Jan41000
Project 12022Q3Feb32500
Project 22022Q3Feb31500
Project 32022Q3Feb31050
Project 12022Q3Feb42550
Project 22022Q3Feb41560
Project 32022Q3Feb41100
Project 12022Q3Mar32600
Project 22022Q3Mar31600
Project 32022Q3Mar31500
Project 12022Q3Mar42800
Project 22022Q3Mar41700
Project 32022Q3Mar41600
  • Hi Srijit ,

    According to your description, here's my solution.

    1.Create a date column.

    Date = FORMAT(DATE('Table'[Year],'Table'[Month Name],1),"yyyy-mm")

    2.Create a rank column based on date.

    Rank = RANKX(FILTER(ALL('Table'),'Table'[Project Name]=MAX('Table'[Project Name])),'Table'[Date],,ASC,Dense)

    3.Create the count per month measure.

    Count per Month = 
    VAR _Cur =
        MAXX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Project Name] = MAX ( 'Table'[Project Name] )
                    && 'Table'[Rank] = MAX ( 'Table'[Rank] )
            ),
            'Table'[Total Count from start]
        )
    VAR _Pre =
        MAXX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Project Name] = MAX ( 'Table'[Project Name] )
                    && 'Table'[Rank]
                        = MAX ( 'Table'[Rank] ) - 1
            ),
            'Table'[Total Count from start]
        )
    RETURN
        IF ( ISBLANK ( _Pre ), BLANK (), _Cur - _Pre )
    

    4.Create the count per qtr measure.

    Count per Qtr = 
    SUMX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Project Name] = MAX ( 'Table'[Project Name] )
                && 'Table'[QTR] = MAX ( 'Table'[QTR] )
        ),
        [Count per Month]
    ) / 2
    

    Get the expected result.

    As there isn't the start value here, so I show it blank.

    I attach my sample below for reference.

     

    Best Regards,
    Community Support Team _ kalyj

     

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

5 Replies

  • Srijit's avatar
    Srijit
    Regular Visitor

    HI amitchandak  Thank for responding

    PLease find the expected column 

     

    Data we HaveExpected to see from calculation
    Project NameYearQTRMonth NameWeekTotal Count from startCount per MonthCount per QTR
    Project 12021Q2Oct32390 Selected QTR - Previous QTR
    Project 22021Q2Oct31390  
    Project 32021Q2Oct3890  
    Project 12021Q2Oct42400  
    Project 22021Q2Oct41400  
    Project 32021Q2Oct4900  
    Project 12021Q2Nov32410  
    Project 22021Q2Nov31410  
    Project 32021Q2Nov3910  
    Project 12021Q2Nov42430  
    Project 22021Q2Nov41440  
    Project 32021Q2Nov4950  
    Project 12021Q2Dec32470  
    Project 22021Q2Dec31450  
    Project 32021Q2Dec3970  
    Project 12021Q2Dec42475  
    Project 22021Q2Dec41455  
    Project 32021Q2Dec4975  
    Project 12022Q3Jan32480  
    Project 22022Q3Jan31475  
    Project 32022Q3Jan3988  
    Project 12022Q3Jan42495  
    Project 22022Q3Jan41490  
    Project 32022Q3Jan41000  
    Project 12022Q3Feb32500  
    Project 22022Q3Feb31500  
    Project 32022Q3Feb31050  
    Project 12022Q3Feb42550  
    Project 22022Q3Feb41560  
    Project 32022Q3Feb41100  
    Project 12022Q3Mar32600  
    Project 22022Q3Mar31600  
    Project 32022Q3Mar31500  
    Project 12022Q3Mar42800Diff of 2800(Max of March for Project 1)-2600 (Max of Feb for Project 1) 
    Project 22022Q3Mar41700Diff of 1700(Max of March for Project 2)-1600 (Max of Feb for Project 2) 
    Project 32022Q3Mar41600Diff of 1600(Max of March for Project 3)-1100 (Max of Feb for Project 3) 
  • Srijit's avatar
    Srijit
    Regular Visitor

    HI All, 

    Is there any chance for a solution for the above issue ??

     

  • Hi Srijit ,

    According to your description, here's my solution.

    1.Create a date column.

    Date = FORMAT(DATE('Table'[Year],'Table'[Month Name],1),"yyyy-mm")

    2.Create a rank column based on date.

    Rank = RANKX(FILTER(ALL('Table'),'Table'[Project Name]=MAX('Table'[Project Name])),'Table'[Date],,ASC,Dense)

    3.Create the count per month measure.

    Count per Month = 
    VAR _Cur =
        MAXX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Project Name] = MAX ( 'Table'[Project Name] )
                    && 'Table'[Rank] = MAX ( 'Table'[Rank] )
            ),
            'Table'[Total Count from start]
        )
    VAR _Pre =
        MAXX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Project Name] = MAX ( 'Table'[Project Name] )
                    && 'Table'[Rank]
                        = MAX ( 'Table'[Rank] ) - 1
            ),
            'Table'[Total Count from start]
        )
    RETURN
        IF ( ISBLANK ( _Pre ), BLANK (), _Cur - _Pre )
    

    4.Create the count per qtr measure.

    Count per Qtr = 
    SUMX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Project Name] = MAX ( 'Table'[Project Name] )
                && 'Table'[QTR] = MAX ( 'Table'[QTR] )
        ),
        [Count per Month]
    ) / 2
    

    Get the expected result.

    As there isn't the start value here, so I show it blank.

    I attach my sample below for reference.

     

    Best Regards,
    Community Support Team _ kalyj

     

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