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
ansa_naz
Continued Contributor
Continued Contributor

Advanced Editor - How to run query if current date is NOT within a list of values?

Hi all

I want to run a query in Advanced Editor, only if the current date is NOT one of the following - 1, 5, 10, 15, 20, 25. Otherwise I dont want the query to run. 

 

I have written the below but I am not getting anywhere very fast:

 

let
    Output = if Date.Day (DateTime.LocalNow()) in (1,5,10,15,20,25) then null else 
    let
    Source = PBILifts
in
    #"PBILifts"

 

 

What am I doing wrong?
Cheers for all help

1 ACCEPTED SOLUTION

My bad.  Please try this approach instead.  I assume PBILifts is an existing query.

 

let
Output = if List.Contains({1,5,10,15,20,25}, Date.Day(DateTime.LocalNow())) then null else PBILifts
in
Output





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
mahoneypat
Employee
Employee

You have two let and only one in. Add in Output

Regards

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


ansa_naz
Continued Contributor
Continued Contributor

Thanks @mahoneypat  I have changed to the below but I still get an error:

 

let
    if Date.Day (DateTime.LocalNow()) in (1,5,10,15,20,25) then null else 
    Source = PBILifts
in
    #"PBILifts"

Any clues please? 

Hi @ansa_naz ,

 

I have tested the method that @ansa_naz  suggested. It works fine in my sample. I add a few document about M. Then you could reference them to learn more about it.

 

Quick tour of the Power Query M formula language 

Power Query Documentation 

 

If you have resolved the problem,  please accept the helpful answers as solution. More people will benefit from this thread. If you still need help, please share a few screenshots and show us the expected results. We will understand clearly.

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

My bad.  Please try this approach instead.  I assume PBILifts is an existing query.

 

let
Output = if List.Contains({1,5,10,15,20,25}, Date.Day(DateTime.LocalNow())) then null else PBILifts
in
Output





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.