Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mterry
Helper V
Helper V

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
1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
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:

7.JPG

Here is sample pbix file, please try it.

 

Best Regards,

Lin

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

View solution in original post

4 REPLIES 4
v-lili6-msft
Community Support
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:

7.JPG

Here is sample pbix file, please try it.

 

Best Regards,

Lin

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

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?

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

 

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

Thanks for the help

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.