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

Power Query "if condition Logic Help"

Hello Community,

Can you please review below and provide your suggestions? I am looking some suggestions using Power Query.

 

Date(mm/dd/yyyy)

12/22/2020

12/23/2020

12/24/2020

1/2/2021

1/3/2021



Logic:1
If Date.Month(DateTime.LocalNow())=1 then it should display data from previous month and previous year

Date(mm/dd/yyyy)

12/22/2020

12/23/2020

12/24/2020


Logic:2
if Date.Month(DateTime.LocalNow())<>1 then it should display only previous month data and same year.

Date(mm/dd/yyyy)

1/2/2021

1/3/2021

 

if
Date.Month(DateTime.LocalNow())=1

then Date.Month ([#"Date(mm/dd/yyyy)"])-1, Date.Year(DateTime.LocalNow())-1

else

Date.Month(DateTime.LocalNow()),Date.Year(DateTime.LocalNow())

Let me know if you need more information.

 

 

2 ACCEPTED SOLUTIONS
mahoneypat
Employee
Employee

Looks like you just want the filter to be for the previous full month.  To do that, just click on the arrow on your date column and make a hard-coded set of date by choosing "Between".  Once that is created, update it with the red text changes below

 

= Table.SelectRows(#"Previous Step", each let today = Date.From(DateTime.LocalNow()) in [Date] >= Date.StartOfMonth(Date.AddMonths(today,-1)) and [Date] <= Date.EndOfMonth(Date.AddMonths(today,-1)))

 

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


View solution in original post

parry2k
Super User
Super User

@tejapowerbi123 solution attached, check steps in transform data. I calculated the start and end date and then used it for the filter. you can tweak the logic as per your need.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

3 REPLIES 3
parry2k
Super User
Super User

@tejapowerbi123 solution attached, check steps in transform data. I calculated the start and end date and then used it for the filter. you can tweak the logic as per your need.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

mahoneypat
Employee
Employee

Looks like you just want the filter to be for the previous full month.  To do that, just click on the arrow on your date column and make a hard-coded set of date by choosing "Between".  Once that is created, update it with the red text changes below

 

= Table.SelectRows(#"Previous Step", each let today = Date.From(DateTime.LocalNow()) in [Date] >= Date.StartOfMonth(Date.AddMonths(today,-1)) and [Date] <= Date.EndOfMonth(Date.AddMonths(today,-1)))

 

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


Hi @mahoneypat  and @parry2k ,

Thank you so much for great suggestions.Both solutions are working for me.

Thanks Again.

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.