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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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 I
Resolver I

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 I
Resolver I

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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