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

In a table after merged query, replace null column value with an existing value for an entity?

In Power BI Desktop, I've merged a two queries:

 

1) Building statistics over time

2) KPI metrics for each building but only contains recent data.

 

What I'm trying to accomplish is use the KPI metrics for the current period but for all of the building periods without this metric, to replace the null value with the current metric (as a benchmark value). Going forward as we capture this KPI, the column can contain the recent data. I originally thought I could use a conditional column but can't build the logic for each building, if value exists for that time period, use the value, if not, use the last value (most recent metric).

 

Is there a way I can accomplish this?

1 ACCEPTED SOLUTION

Hi @Humblelistener ,

 

In the score query, the steps create a numeric column YEAR-QTR

20200130_Score.png

 

Similarly, I create the same column YEAR-QTR in the Building Stats query

20200130_Bulding Stats_01.png

 

Merge the two queries using the BUILDING column...

20200130_Bulding Stats_02.png

 

...and expand the Scores YEAR-QTR.

20200130_Bulding Stats_03.png

 

The conditional column marks the relevant rows, where the Building Stats.YEAR-QTR <= Scores.YEAR-QTR

20200130_Bulding Stats_04.png

 

Than you can filter on the relevant rows.

20200130_Bulding Stats_05.png

Group the rows to get the last/nearest Scores.YEAR-QTR

20200130_Bulding Stats_06.png

 

Now you can merge the two queries related to the BUILDING and (the latest) Scores.YEAR-QTR columns.

20200130_Bulding Stats_07.png

Expand Scores column to get the Score value

20200130_Bulding Stats_08.png

 

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


View solution in original post

10 REPLIES 10

Hi @Humblelistener ,

 

can you provide some sample data?

I think you have to do another merge with the last value, to use your conditional column.

 

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Hello Marcus,

 

Thank you for the reply! Here's a sample of the data.

 

Building Month Merged.Building Merged.Score

A 1/19 null null

A 2/19 null null

A 3/19 null null

A 4/19 null null

A 5/19 null null

A 6/19 null null

A 7/19 null null

A 8/19 null null

A 9/19 A 23

A 10/19 A 23

A 11/19 A 23

A 12/19 A 23

A 1/20 A 26

B 5/19 null null

B 6/19 null null

B 7/19 null null

B 8/19 null null

B 9/19 B 30

B 10/19 B 30

B 11/19 B 30

B 12/19 B 30

B 1/20 B 28

 

So basically there is a table with Building statistics broken out by month then merged columns from another table with a "Score". What I'd like to do is create a custom column called "Based Score" and for each building, for the months where there is a "score" value, to keep what is there (9/19 - 1/20) but for the months where there is no score (1/19 - 8/19), to replace the null value with the last month with a score (in this case, 9/19). Please note in the example above that building "B" is a newer building that came online as of 5/19 so the condition needs to be able to account for buildings with less than 12 months.

 

THANKS!!!

 

Hi @Humblelistener ,

 

check this PBIX

 

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Marcus,

 

I can sort of follow the logic from your file but if you can see the original sample data I provided, the merged data did not have a month field, only the building name and the score so I'm not entirely sure how to do the level of cross-filtering you've demonstrated via your file?

 

Kind regards,

Hi @Humblelistener ,

 

could you provide the "Base" sample data for the "Building statistics" and "Score"?

When I look at your merge data there is a month field...

MergeData_Building.png

... and you also described it accordingly.

Building_Month.png

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Hello Marcus,

 

That's because after the merge, it associated a month to the Building Score.

 

This is what the Building Stats data looks like (which has months):

 

YEARQTRMONTHBUILDINGSQFTREGIONMANAGERSTATUSOCCUPANCY
2019Q1Jan-19A5000AmericasSmith, JohnPlanned5
2019Q1Feb-19A5000AmericasSmith, JohnActive11
2019Q1Mar-19A5000AmericasSmith, JohnActive6
2019Q2Apr-19A5000AmericasSmith, JohnActive7
2019Q2May-19A5000AmericasSmith, JohnActive6
2019Q2Jun-19A5000AmericasSmith, JohnActive11
2019Q3Jul-19A5000AmericasSmith, JohnActive15
2019Q3Aug-19A5000AmericasSmith, JohnActive10
2019Q3Sep-19A5000AmericasSmith, JohnActive9
2019Q4Oct-19A5000AmericasSmith, JohnActive8
2019Q4Nov-19A5000AmericasLee, RobActive8
2019Q4Dec-19A5000AmericasLee, RobActive6
2020Q1Jan-20A5000AmericasLee, RobActive7
2019Q1Jan-19B9000AsiaHo, MikePlanned20
2019Q1Feb-19B9000AsiaHo, MikeActive18
2019Q1Mar-19B9000AsiaHo, MikeActive22
2019Q2Apr-19B9000AsiaHo, MikeActive24
2019Q2May-19B9000AsiaHo, MikeActive19
2019Q2Jun-19B9000AsiaHo, MikeActive20
2019Q3Jul-19B9000AsiaHo, MikeActive23
2019Q3Aug-19B9000AsiaHo, MikeActive26
2019Q3Sep-19B9000AsiaHo, MikeActive21
2019Q4Oct-19B9000AsiaHo, MikeActive20
2019Q4Nov-19B9000AsiaHo, MikeActive22
2019Q4Dec-19B9000AsiaHo, MikeActive21
2020Q1Jan-20B9000AsiaHo, MikeActive22
2019Q1Jan-19C6800EuropeRustov, VladPlanned14
2019Q1Feb-19C6800EuropeRustov, VladActive16
2019Q1Mar-19C6800EuropeRustov, VladActive17
2019Q2Apr-19C6800EuropeRustov, VladActive19
2019Q2May-19C6800EuropeRustov, VladActive20
2019Q2Jun-19C6800EuropeRustov, VladActive11
2019Q3Jul-19C6800EuropeRustov, VladActive12
2019Q3Aug-19C6800EuropeRustov, VladActive12
2019Q3Sep-19C6800EuropeOro, MiguelActive14
2019Q4Oct-19C6800EuropeOro, MiguelActive16
2019Q4Nov-19C6800EuropeOro, MiguelActive17
2019Q4Dec-19C6800EuropeOro, MiguelActive19
2020Q1Jan-20C6800EuropeOro, MiguelActive20

 

This is what the Scores data looks like:

 

YEARQTRBUILDINGSCORE
2019Q2A23
2019Q3A23
2019Q4A23
2020Q1A26
2019Q3B18
2019Q4B18
2020Q1B28
2019Q4C22
2020Q1C23

 

So, the merge is based on the matching the Year, Quarter, and Building Name. So the merged data looks like this:

 

YEARQTRMONTHBUILDINGSQFTREGIONMANAGERSTATUSOCCUPANCYMerged.BuildingMerged.Score
2019Q1Jan-19A5000AmericasSmith, JohnPlanned5nullnull
2019Q1Feb-19A5000AmericasSmith, JohnActive11nullnull
2019Q1Mar-19A5000AmericasSmith, JohnActive6nullnull
2019Q2Apr-19A5000AmericasSmith, JohnActive7A23
2019Q2May-19A5000AmericasSmith, JohnActive6A23
2019Q2Jun-19A5000AmericasSmith, JohnActive11A23
2019Q3Jul-19A5000AmericasSmith, JohnActive15A23
2019Q3Aug-19A5000AmericasSmith, JohnActive10A23
2019Q3Sep-19A5000AmericasSmith, JohnActive9A23
2019Q4Oct-19A5000AmericasSmith, JohnActive8A23
2019Q4Nov-19A5000AmericasLee, RobActive8A23
2019Q4Dec-19A5000AmericasLee, RobActive6A23
2020Q1Jan-20A5000AmericasLee, RobActive7A26
2019Q1Jan-19B9000AsiaHo, MikePlanned20nullnull
2019Q1Feb-19B9000AsiaHo, MikeActive18nullnull
2019Q1Mar-19B9000AsiaHo, MikeActive22nullnull
2019Q2Apr-19B9000AsiaHo, MikeActive24nullnull
2019Q2May-19B9000AsiaHo, MikeActive19nullnull
2019Q2Jun-19B9000AsiaHo, MikeActive20nullnull
2019Q3Jul-19B9000AsiaHo, MikeActive23B18
2019Q3Aug-19B9000AsiaHo, MikeActive26B18
2019Q3Sep-19B9000AsiaHo, MikeActive21B18
2019Q4Oct-19B9000AsiaHo, MikeActive20B18
2019Q4Nov-19B9000AsiaHo, MikeActive22B18
2019Q4Dec-19B9000AsiaHo, MikeActive21B18
2020Q1Jan-20B9000AsiaHo, MikeActive22B28
2019Q1Jan-19C6800EuropeRustov, VladPlanned14nullnull
2019Q1Feb-19C6800EuropeRustov, VladActive16nullnull
2019Q1Mar-19C6800EuropeRustov, VladActive17nullnull
2019Q2Apr-19C6800EuropeRustov, VladActive19nullnull
2019Q2May-19C6800EuropeRustov, VladActive20nullnull
2019Q2Jun-19C6800EuropeRustov, VladActive11nullnull
2019Q3Jul-19C6800EuropeRustov, VladActive12nullnull
2019Q3Aug-19C6800EuropeRustov, VladActive12nullnull
2019Q3Sep-19C6800EuropeOro, MiguelActive14nullnull
2019Q4Oct-19C6800EuropeOro, MiguelActive16C22
2019Q4Nov-19C6800EuropeOro, MiguelActive17C22
2019Q4Dec-19C6800EuropeOro, MiguelActive19C22
2020Q1Jan-20C6800EuropeOro, MiguelActive20C23

 

So, the Month is derived from the Building data. Hope this helps explain things. Thanks!

Hi @Humblelistener,

 

check this.

PBIX

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


I've tried to mimic the file you provided to the actual datasets that I'm working and I'm not getting the desired results. I guess I'm not following the logic around the steps used? Would you be so kind to break out the steps and what it accomplishes? 

 

VERY MUCH APPRECIATED!!!

Hi @Humblelistener ,

 

In the score query, the steps create a numeric column YEAR-QTR

20200130_Score.png

 

Similarly, I create the same column YEAR-QTR in the Building Stats query

20200130_Bulding Stats_01.png

 

Merge the two queries using the BUILDING column...

20200130_Bulding Stats_02.png

 

...and expand the Scores YEAR-QTR.

20200130_Bulding Stats_03.png

 

The conditional column marks the relevant rows, where the Building Stats.YEAR-QTR <= Scores.YEAR-QTR

20200130_Bulding Stats_04.png

 

Than you can filter on the relevant rows.

20200130_Bulding Stats_05.png

Group the rows to get the last/nearest Scores.YEAR-QTR

20200130_Bulding Stats_06.png

 

Now you can merge the two queries related to the BUILDING and (the latest) Scores.YEAR-QTR columns.

20200130_Bulding Stats_07.png

Expand Scores column to get the Score value

20200130_Bulding Stats_08.png

 

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Hi @Humblelistener ,

 

found a much simpler variant today.

Use Fill: https://www.excelcampus.com/library/fill-down-blank-null-cells-power-query/

Fill_UP.png

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


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.