Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Using EOMONTH to find quarterly sum

Hello Community, 

 

I have an odd situation where I have to use snapshot data to get particular results.   In this case, reconciled information from our accounting system.   It is reported out as "snapshots"  (not the traditional daily transactional format normally seen). 

 

The measure below results in the visual you see.   Note that the filters I have selected just tell the visual which accounts to use in the sum of the "actual value" expression.  

 

The formula below works perfectly because the "eomonth" function captures the snapshot of each month's end total.

 

However, our system does not capture results at a quarterly level, and because the data is not transactional daily data, the normal time intelligence functions I do not think will work.   The eomonth function works because it looks at the ending "actual value" of the month  (which is the total sum for that month).  

 

I somehow need to adapt this formula (or some other method) to provide quarterly results and would appreciate any guidance.   Thanks! 

 

Monthly Reconciled Measure =
VAR _year = SELECTEDVALUE(Dates[Year])
VAR _month = SELECTEDVALUE(Dates[MonthName])
VAR _date = CALCULATE(MIN(Dates[Date]), FILTER(ALL(Dates), Dates[Year] = _year && Dates[MonthName] = _month))
VAR _lastDate = EOMONTH(_date,-0)+5//assumes that numbers will be fully reconciled after 5 days. Values before 5 days may not be fully reconciled

RETURN

CALCULATE(SUM(Flu_Snapshots[Actual Value]),FILTER(ALL(Dates[Date]), Dates[Date] = _lastDate))


  • MFelix's avatar
    MFelix
    6 years ago

    Hi Anonymous ,

     

    Believe that you can do two things:

    1. Make a measure for quarter values (DAX)
    2. Make a column with the daily figures (M Language)

     

    Option 1.

    • Create the following columns on your calendar table:
    Quarter = "Q"&QUARTER([Date] -5)
    End_of_month = EOMONTH([Date]-5;0)
    //Forcing in both column to pick up th date from 5 days earlier as you have in the monthly calculation.
    • Add the measure below for the Quartely calculation:
    Quarter Reconciled Measure = 
    SUMX (
        SUMMARIZE ( Dates; Dates[End_of_month]; "@Date_Selection"; MAX ( Dates[Date] ) );
        CALCULATE (
            SUM ( FLU_Snapshots[Actual_Value] );
            FILTER (
                ALL ( FLU_Snapshots[As of date] );
                FLU_Snapshots[As of date] = MAX ( [@Date_Selection] )
            )
        )
    )

     

    Option 2.

    You also may make some query adaptations to get the daily figures:

    • Add a step after the last step of your query
      • Rigth click the last step on the query settings and select Insert Step after
      • Rename this step for example to ====== (this will give you the notion of where you started to add new changes)
    • Add a custom column with the following code:
    PreviousDay =[As of date] - #duration(1,0,0,0)
    • Remove the As of Date column
    • Insert a Merge Querie
      • Do a Merger with the same querie
      • Select all columns that are unique identifiers for each row
      • On my example only have two (Description and As of Date)
      • Do not select the value or any other columns that change within the day otherwise you will get blank values
      • Select the left Join
    • On the formula bar you will have:
      • Table.NestedJoin(#"Step Name", {"Description", "As of date"}, #"Step Name", {"Description", "PreviousDay"}, "Removed Columns", JoinKind.LeftOuter)
      • Replace the first Step Name (information highligted above) by the name of the step before the custom step ( ======)
    • Expand the Actuals value from New column
    • Add a new custom column:
    [Actual_Value]-[Removed Columns.Actual_Value]
    • Remove the column that you expanded before in my case [Removed Columns.Actual_Value]

    Now you have daily values for all your KPI not sure if they are of any help but it's one way of getting daily values.

     

    See attach PBIX file.

15 Replies

  • Hi Anonymous ,

     

    I assume you have a date column on your dataset correct? 

     

    If you are using a calendar table to make the relationship with the dataset then you can use the normal time inteligence measures the only thing you need to assure is that the calednar table as continous dates from january 1st to december 31st.

     

    Can you share you model setup please?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Miguel, Yes, I have a date table (you can see it referenced in the formula).   It is connected to "as of date" on the Flu_Snapshots table.   There are other tables but they are not relevant here.    Only the Dates table and the Snapshots table are involved. 

       

      • MFelix's avatar
        MFelix
        Super User

        Hi Anonymous ,

         

        If you make the calculation based on the timeinteliggence it will work properly:

         

        QTD = TOTALQTD(SUM(Flu_Snapshots[Actual Value]);Dates[Date])

         

        This is just an example and can be adjusted, but no need to use EOMONTH formula, except if you don't want to use normal quarters

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    Click the Quarter Formulas Button.
    Select the 1st Quarter cell where you want the formulas to be created and click OK. ...
    Select the cell that contains month 1 data and click OK. ...
    The SUM formulas will be created in the Q1 cell and the four cells to the right of it.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Lewis, Sorry, I am not following.  

       

      Which quarters formula button?  Where is that?     And what cells?   I am using Power Bi