Forum Discussion
Macaurly
8 years agoRegular Visitor
Power Query choose a step to create based on a condition
Hello, I have managed to filter my table using Table.SelectRows so that I only show rows where a Date field lies between two dates for payroll purposes. So as a contextual example, I want to see al...
Anonymous
8 years agoNot applicable
Macaurly,
Change your code to the following and check if you get expected result.
let
Source = #"Timesheets SQL",
#"Filtered1" = Table.SelectRows(Source, each ([EntryDate] >= #date(2018, Date.Month(Date.AddMonths(DateTime.LocalNow(), -1)), 11) and [EntryDate] < #date(2018, Date.Month(DateTime.LocalNow()), 11))),
#"Grouped Rows1" = Table.Group(#"Filtered1", {"SharepointHeaderID", "Employee_ID", "Selection_1_Value", "Selection_2_Value"}, {{"Weekly Hours", each List.Sum([Hours]), type number}}),
#"Filtered2"= Table.SelectRows(Source, each ([EntryDte] >= #date(2018, Date.Month(DateTime.LocalNow()), 11) and [EntryDate] < #date(2018, Date.Month(Date.AddMonths(DateTime.LocalNow(), 1), 11))),
#"Grouped Rows2" = Table.Group(#"Filtered2", {"SharepointHeaderID", "Employee_ID", "Selection_1_Value", "Selection_2_Value"}, {{"Weekly Hours", each List.Sum([Hours]), type number}}),
result =
if Date.Day(DateTime.LocalNow()) < 11
then #"Grouped Rows1"
else #"Grouped Rows2"
in
#"result"
Reference:
https://community.powerbi.com/t5/Community-Blog/Conditional-Code-Branching-in-Power-BI-Query-if-then-else-gt/ba-p/39998
Regards,
Lydia
Macaurly
8 years agoRegular Visitor
Hi Anonymous Lydia,
Thank you for offering a solution.
I have tried the code you suggested but I still get a 'Token Literal expected' warning which highlights the word 'if'.
Thanks,
Macaurly.
- Anonymous8 years agoNot applicable
Macaurly,
I would recommend you re-check the code in the PBIX sample file of the above blog, and then change your code.
If you still get error, please help to post screenshot about your code, and share your PBIX file to me if it is possible. You can share PBIX file via Private Message.
Regards,
Lydia