Forum Discussion

Abs_N's avatar
Abs_N
Frequent Visitor
4 years ago
Solved

DAX Measure to calculate month end value dynamically

Hi,

I have power bi report and would like to create a DAX measure to calculate the SLA % of the total but for the last month dynamically.

Here is a sample of my data:


Month Year       Within        SLA Total           % within SLA
Sep-21                    10              50                      20
Oct-21                      5               50                      10
Nov-21                     7             100                         7

 

I would like to create a measure to work out the Nov21 % SLA
but I would like the calculation to be dynamic so that is uses the last month measure.

So when we run the report is run again in say January it uses Dec21 for calculating the %SLA.

Thanks

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Abs_N ,

     

    According to your description, I think you are going to calculate the ratio value for the previous month.

     

    You can try this measure:

    % previous month = var _start=EOMONTH(TODAY(),-2)
    var _end=EOMONTH(TODAY(),-1)
    return DIVIDE(CALCULATE(SUM('Table'[Within]),FILTER('Table',[Month Year]<=_end&&[Month Year]>_start)),CALCULATE(SUM('Table'[SLA Total]),FILTER('Table',[Month Year]<=_end&&[Month Year]>_start)))

    EOMONTH function returns the date in datetime format of the last day of the month, before or after a specified number of months.

    Here's the result.

     

    Best Regards,

    Stephen Tao

     

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

     

     

5 Replies

  • Abs_N's avatar
    Abs_N
    Frequent Visitor

    Hi Greg_Deckler ,

     

    no the percentage is 7% however I want the calculation to be dynamic in that it always uses the month end measure

    so say we have a card for this month end measure and it will return 7% 
    then when we run the report again after month and the dataset has Decemeber data the card will automatically pick up Decemebers data and show the new %. 

     

    I want the measure to the automatically use the latest month data.

    • Greg_Deckler's avatar
      Greg_Deckler
      Icon for Community Champion rankCommunity Champion

      Abs_N Oh, then you just need Lookup Min/Max where you find your max date value and then grab the items from that row, like below. Best if you have an actual date column or index column to find the "max".

      Measure =
        VAR __Last = MAX('Table'[Month Year])
        VAR __Within = MAXX(FILTER('Table',[Month Year]=__Last),[Within])
        VAR __SLATotal = MAXX(FILTER('Table',[Month Year]=__Last),[SLA Total])
      RETURN
        __Within / __SLATotal * 100

       

      • Abs_N's avatar
        Abs_N
        Frequent Visitor

        Hi Greg_Deckler 
        I think we are nearly there . . .

        The underlying data is as follows 

         

        Month YearWithinTotal
        Sep-2101
        Oct-2111
        Nov-2111

         

        The original table is a summary 

         

        The "Within" is a sum and the total is a count of all the items.

        I have tried checking the within variable but I think my syntax is incorrect.
        Here is what I have at the moment . . 

        LastMonthPercentage =
        VAR __Last = max('AlertData'[Period])
        VAR __Within = MAXX(FILTER('AlertData',[Period])=__Last, sum(AlertData[WithinSLA]))
        RETURN
        __Within
         
        ERROR - The expression refers to multiple columns. multiple columns cannot be converted to a scalar value

         

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Abs_N ,

     

    According to your description, I think you are going to calculate the ratio value for the previous month.

     

    You can try this measure:

    % previous month = var _start=EOMONTH(TODAY(),-2)
    var _end=EOMONTH(TODAY(),-1)
    return DIVIDE(CALCULATE(SUM('Table'[Within]),FILTER('Table',[Month Year]<=_end&&[Month Year]>_start)),CALCULATE(SUM('Table'[SLA Total]),FILTER('Table',[Month Year]<=_end&&[Month Year]>_start)))

    EOMONTH function returns the date in datetime format of the last day of the month, before or after a specified number of months.

    Here's the result.

     

    Best Regards,

    Stephen Tao

     

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