Forum Discussion
Display First and Last date based on two week index
- Anonymous4 years ago
Hi Anonymous ,
Please try to use the what-if parameter. You can interact with the variable as a slicer, and visualize and quantify different key values in your reports.
Here's my solution.
First, I created the Payroll Index from Jan20 on my own way.
Then, create a what-if parameter on the Modeling tab.
Set your own parameters according to your needs, here my maximum value is set to 26.
You can get a slider and a calculated table.
Create a relationship between two tables, then you can filter through the slider.
Now you can create a measure to get the text "1/1/2020 - 1/14/2020" to be displayed when the slider is selected to 0.
Measure = MIN('Calendar'[Date])&"-"&MAX('Calendar'[Date])Reference: Use what-if parameters to visualize variables - Power BI | Microsoft Docs
You can check more details from my attachment.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
You have 2 options.
1 - simple solution
Select Source step in my query and replace all the text with name of your query (if you don't know how to do it you can select your query and right click it and choose Reference
pq will create reference to your query. Copy thos reference and paste to Source step).
2 - more complicated - Open your query in advanced editor and delete in statement and name of last step. Next paste the code below
,
Custom1a = List.Buffer(List.Zip({Source[Date],Source[#"Payroll index from Jan2020"]})),
Custom2a = Source,
#"Added Customa" = Table.AddColumn(Custom2a, "DateMin", each List.Min(List.Transform(List.Select(Custom1a, (x)=>x{1}=[#"Payroll index from Jan2020"]), each _{0}))),
#"Added Custom1a" = Table.AddColumn(#"Added Customa", "DateMax", each List.Max(List.Transform(List.Select(Custom1a, (x)=>x{1}=[#"Payroll index from Jan2020"]), each _{0})))
in
#"Added Custom1a"and replace words Source with the name of last step from your query.
Hope it helps.
Artur
- Anonymous4 years agoNot applicable
The only problem with that is my "Date" table was created in DAX, thus has no table in power query.
- artpil4 years agoResolver II
You have new options:
1. Create date table in power query - heres the code to create table from 01-06-2020 until current day
let Source = Table.FromList(List.Numbers(Number.From(#date(2020,1,6)),Number.From( Date.From( DateTime.LocalNow()))-Date.DayOfWeek( Date.From(DateTime.LocalNow()),Day.Monday)+7-Number.From(#date(2020,1,6))), Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Added Custom2" = Table.AddColumn(Source, "Payroll index from Jan2020", each Number.IntegerDivide(([Column1]-43836),7)), #"Renamed Columns" = Table.RenameColumns( Table.TransformColumnTypes(#"Added Custom2",{{"Column1", type date}}),{{"Column1", "Date"}}), Custom1 = List.Buffer(List.Zip({#"Renamed Columns"[Date],#"Renamed Columns"[#"Payroll index from Jan2020"]})), Custom2 = #"Renamed Columns", #"Added Custom" = Table.AddColumn(Custom2, "DateMin", each List.Min(List.Transform(List.Select(Custom1, (x)=>x{1}=[#"Payroll index from Jan2020"]), each _{0}))), #"Added Custom1" = Table.AddColumn(#"Added Custom", "DateMax", each List.Max(List.Transform(List.Select(Custom1, (x)=>x{1}=[#"Payroll index from Jan2020"]), each _{0}))) in #"Added Custom1"2. Post your issue on DAX commands and tips forum.
Artur