Forum Discussion

mterry's avatar
mterry
Helper V
7 years ago
Solved

DAX for monthly data with missing values

I have output data for several locations spanning multiple years (a portion of the data is attached). Some locations have consistent output throughout the year, some will have a change at one point during the year. If there isn't a change, then there is no data recorded in the 'date' column - the only date data to go off of would be the year. What I'm trying to do is show a monthly output calculation rather than annual. It would sum the total output each month and incorporate the changes & dates. So for the sample data set, the output for January 2018 would be 169,905, but for March 2018 it would be 155,906 to reflect the changes that took place in Tag A and Tag N in Feb. 

 

TagYearBeginning OutputDateEnding Output
A2018149152/22/20186806
B2018504711/1/20183641
C201835375 35375
D20182707 2707
E20188256 8256
F20189400 9400
G20184468 4468
H20184240 4240
I201822910/31/2018 
J201812022 12022
K20186825 6825
L20187533 7533
M20188338 8338
N201858902/28/2018 
O2018942 942
P20182191 2191
Q20183608 3608
R201810720 10720
S20186251 6251
T201815600 15600
U2018 1/1/20185348
A20196806 6806
B201936415/1/20195047
C2019353751/14/201938541
D20192707 2707
E20198256 8256
F20199400 9400
G20194468 4468
H20194240 4240
I201912022 12022
J20196825 6825
K20197533 7533
L20198338 8338
M2019942 942
N2019219112/31/2019 
O20193608 3608
P201910720 10720
Q20196251 6251
R201915600 15600
S20195348 5348
  • hi, mterry 

    Based on my research, you could try this way:

    Step1:

    Create a dim year month date table or you could just use this formula to create a new dim table

    Dim Date = 
    SELECTCOLUMNS (
        FILTER ( CALENDAR ( "2018-01-01", "2019-12-31" ), DAY ( [Date] ) = 1 ),
        "Year No", YEAR ( [Date] ),
        "Month No", MONTH ( [Date] ),
        "Year Month", YEAR ( [Date] ) * 100
            + MONTH ( [Date] )
    )

    Step2:

    Add month column for date column in your basic table

    Step3:

    Use this formula to create a new table

    Table = FILTER(GENERATE(Basic,'Dim Date'),Basic[Year]='Dim Date'[Year No])

    Step4:

    In the new table, create a real outout column

    Real Output = IF('Table'[Month]<='Table'[Month No],'Table'[Ending Output],'Table'[Beginning Output])

    Step5:

    Drag Year month column and real output column from the new table into a visual

    Result:

    Here is sample pbix file, please try it.

     

    Best Regards,

    Lin

4 Replies

  • v-lili6-msft's avatar
    v-lili6-msft
    Community Support

    hi, mterry 

    Based on my research, you could try this way:

    Step1:

    Create a dim year month date table or you could just use this formula to create a new dim table

    Dim Date = 
    SELECTCOLUMNS (
        FILTER ( CALENDAR ( "2018-01-01", "2019-12-31" ), DAY ( [Date] ) = 1 ),
        "Year No", YEAR ( [Date] ),
        "Month No", MONTH ( [Date] ),
        "Year Month", YEAR ( [Date] ) * 100
            + MONTH ( [Date] )
    )

    Step2:

    Add month column for date column in your basic table

    Step3:

    Use this formula to create a new table

    Table = FILTER(GENERATE(Basic,'Dim Date'),Basic[Year]='Dim Date'[Year No])

    Step4:

    In the new table, create a real outout column

    Real Output = IF('Table'[Month]<='Table'[Month No],'Table'[Ending Output],'Table'[Beginning Output])

    Step5:

    Drag Year month column and real output column from the new table into a visual

    Result:

    Here is sample pbix file, please try it.

     

    Best Regards,

    Lin

    • mterry's avatar
      mterry
      Helper V

      I should have noted that I do have a date table already in use in this report, my apologies. I'll play around with your solution in that table and see if that solves it - seems like that may make more sense than to create a measure?

      • v-lili6-msft's avatar
        v-lili6-msft
        Community Support

        hi, mterry 

        Yes, you'd better create a year-month date dim table as above, that will make the solution easier to understand.

         

        Best Regards,

        Lin