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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
user_34
Frequent Visitor

Dynamically Column Header as a today date,yesterday date and day before yesterday date

Hi Everyone

 

I have a date picker in Power BI and I want to display the sales of each product on the selected day
plus the day before the selected date and the day before yesterday as shown in the image. and each row should display the target of sales met of that product on specific days in colored bullets that is green specifies that my target on a specific date was met and red specifies it was not met and I want to make dates as a header.

Attached the demo data.

 

user_34_0-1712071548790.png

 

product.xlsx

1 ACCEPTED SOLUTION
AnushaSri
Resolver II
Resolver II

Create a Dynamic Table for Custom dates in Power query as follows

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCslPSaxUitWJVopMLS5JLYLxnFLT8otSFZAEYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Day = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Day", type text}}),
#"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Date", each if [Day] = "Today" then DateTime.LocalNow() else if [Day] = "Yesterday" then Date.AddDays(DateTime.LocalNow(),-1) else if [Day] = "Before Yesterday" then Date.AddDays(DateTime.LocalNow(),-2) else null),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Conditional Column",{{"Date", type date}}),
#"Duplicated Column" = Table.DuplicateColumn(#"Changed Type1", "Day", "Day - Copy"),
#"Duplicated Column1" = Table.DuplicateColumn(#"Duplicated Column", "Date", "Date - Copy"),
#"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Duplicated Column1", {{"Date - Copy", type text}}, "en-GB"),{"Day - Copy", "Date - Copy"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged")
in
#"Merged Columns"
This creates a table as follow 

AnushaSri_0-1712075020886.png

Now create a relationship between this Dynamic table and Your Original Date table.
Use Merged Column as Table Headers.

@user_34 Please accept solution , if it helps to solve your issue.

View solution in original post

2 REPLIES 2
user_34
Frequent Visitor

Thanks it worked

AnushaSri
Resolver II
Resolver II

Create a Dynamic Table for Custom dates in Power query as follows

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCslPSaxUitWJVopMLS5JLYLxnFLT8otSFZAEYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Day = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Day", type text}}),
#"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Date", each if [Day] = "Today" then DateTime.LocalNow() else if [Day] = "Yesterday" then Date.AddDays(DateTime.LocalNow(),-1) else if [Day] = "Before Yesterday" then Date.AddDays(DateTime.LocalNow(),-2) else null),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Conditional Column",{{"Date", type date}}),
#"Duplicated Column" = Table.DuplicateColumn(#"Changed Type1", "Day", "Day - Copy"),
#"Duplicated Column1" = Table.DuplicateColumn(#"Duplicated Column", "Date", "Date - Copy"),
#"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Duplicated Column1", {{"Date - Copy", type text}}, "en-GB"),{"Day - Copy", "Date - Copy"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged")
in
#"Merged Columns"
This creates a table as follow 

AnushaSri_0-1712075020886.png

Now create a relationship between this Dynamic table and Your Original Date table.
Use Merged Column as Table Headers.

@user_34 Please accept solution , if it helps to solve your issue.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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