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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

"Fill in" values between dates

Hi,

 

I am currently trying to create a visual but struggling with some time intelligence calculations. My data has the following structure:

BillIDLegislation StatusYear
166Proposed2009
166Tabled2009
166Passed2011
166Implemented2012
193Proposed2011
193Tabled2011
193Passed2011
193Implemented2014

 

However, in order to make a visual I need to "fill in" the values where there are missing years for each BillID:

BillIDLegislation StatusYear
166Proposed2009
166Tabled2009
166Tabled2010
166Passed2011
166Implemented2012
193Proposed2011
193Tabled2011
193Passed2011
193Passed2012
193Passed2013
193Implemented2014

 

Does anyone know some smart DAX that could solve this problem? For reference, this is (roughly) the visual I am trying to create:
2020-08-20_18-13-05.jpg

 

 

 

 

Any help appreciated, thanks!

3 ACCEPTED SOLUTIONS

@Anonymous Ok, I have another solution for you:

 
Status Measure = COALESCE(min(Gap[Status]),
CALCULATE(min(Gap[Status]),PREVIOUSYEAR('Calendar'[Date])),
CALCULATE(min(Gap[Status]),PREVIOUSYEAR(PREVIOUSYEAR('Calendar'[Date]))),
CALCULATE(min(Gap[Status]),PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR('Calendar'[Date])))),
CALCULATE(min(Gap[Status]),PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR('Calendar'[Date]))))),
CALCULATE(min(Gap[Status]),PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR('Calendar'[Date]))))))
)
 
This one will look at this year, and then up to 5 years back for the status to bring forward. 


Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

View solution in original post

Hi @Anonymous ,

 

DataZoe has provided  a clear method but you need a calendar table. Or you can create a year table as mentioned by him above. Then use the following measure based on your sample data:

 

Measure = var a = MAX('All Years'[Value]) return COALESCE(MAX('Table'[Legislation Status]),CALCULATE(MAX('Table'[Legislation Status]),ALLEXCEPT('Table','Table'[BillID]),'Table'[Year] = a-1),CALCULATE(MAX('Table'[Legislation Status]),ALLEXCEPT('Table','Table'[BillID]),'Table'[Year] = a-2))

 

Capture2.PNG

 

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EZMKiHLutDZJo0JaoX7hR7QBON50OxZ57PjBM6gbiiqw8A?e=no0CV8

 

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

 

Best Regards,

Dedmon Dai

 

 

View solution in original post

Anonymous
Not applicable

Hi Everyone,

 

Apologies for not replying sooner but I decided to instead create a Year & BillID scaffold the data warehouse before importing into Power BI.

 

This means I dont need to create DAX with a fixed number of dates and can instead work dynamically.

 

Thanks for the suggestions.

View solution in original post

5 REPLIES 5
DataZoe
Microsoft Employee
Microsoft Employee

@Anonymous You could create a calculated table with all the years you need, then create a relationship to the table. 

 

Modeling --> New Table

All Years = GENERATESERIES(minx('Calendar','Calendar'[Year]),maxx('Calendar','Calendar'[Year]),1)

 

Once you have that, change out the year on the visual to the new table's year. Then right-click on the year in the field list, and choose "Show items with no data"

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

Anonymous
Not applicable

Hi @DataZoe,

 

Thanks for the response. Unfortunatley that hasn't solved the issue as I am looking to actually "fill in" values for the cells, where if the value for the next year is blank, I fill in the value for the previous year.

 

Sorry for the crude picture editing but it would be from this:

Davidson919_1-1598002976306.png

to this:

Davidson919_2-1598003084890.png

 

Hi @Anonymous ,

 

DataZoe has provided  a clear method but you need a calendar table. Or you can create a year table as mentioned by him above. Then use the following measure based on your sample data:

 

Measure = var a = MAX('All Years'[Value]) return COALESCE(MAX('Table'[Legislation Status]),CALCULATE(MAX('Table'[Legislation Status]),ALLEXCEPT('Table','Table'[BillID]),'Table'[Year] = a-1),CALCULATE(MAX('Table'[Legislation Status]),ALLEXCEPT('Table','Table'[BillID]),'Table'[Year] = a-2))

 

Capture2.PNG

 

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EZMKiHLutDZJo0JaoX7hR7QBON50OxZ57PjBM6gbiiqw8A?e=no0CV8

 

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

 

Best Regards,

Dedmon Dai

 

 

Anonymous
Not applicable

Hi Everyone,

 

Apologies for not replying sooner but I decided to instead create a Year & BillID scaffold the data warehouse before importing into Power BI.

 

This means I dont need to create DAX with a fixed number of dates and can instead work dynamically.

 

Thanks for the suggestions.

@Anonymous Ok, I have another solution for you:

 
Status Measure = COALESCE(min(Gap[Status]),
CALCULATE(min(Gap[Status]),PREVIOUSYEAR('Calendar'[Date])),
CALCULATE(min(Gap[Status]),PREVIOUSYEAR(PREVIOUSYEAR('Calendar'[Date]))),
CALCULATE(min(Gap[Status]),PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR('Calendar'[Date])))),
CALCULATE(min(Gap[Status]),PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR('Calendar'[Date]))))),
CALCULATE(min(Gap[Status]),PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR(PREVIOUSYEAR('Calendar'[Date]))))))
)
 
This one will look at this year, and then up to 5 years back for the status to bring forward. 


Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

August Carousel

Fabric Community Update - August 2024

Find out what's new and trending in the Fabric Community.