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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
PavaniD
Helper I
Helper I

Date slicer with few conditions

Hello

 

I have a SQL query ,under the WHERE condition the date slicer have few conditions.How can i achieve that in power bi?Below is the query.

 

WHERE

(FA.CRE_DTTM) >=
CASE WHEN #PROMPT('PARAM1')# = TO_CHAR(SYSDATE , 'YYYY-MM-DD') THEN (CURRENT_DATE - 90 )
ELSE TO_DATE(#PROMPT('PARAM1')#, 'YYYY-MM-DD')
END
AND (FA.CRE_DTTM) <=
CASE WHEN #PROMPT('PARAM2')# = TO_CHAR(SYSDATE, 'YYYY-MM-DD') THEN (CURRENT_DATE +1)
ELSE TO_DATE(#PROMPT('PARAM2')#, 'YYYY-MM-DD') +1
END

4 REPLIES 4
PavaniD
Helper I
Helper I

Thanks  @rajendraongole1. Can I create measure or column ?
also I need only date and cre_dttm has only date.

Hi @PavaniD you have to create a parameters in Power query editor as like PARAM1 and param2.

 

Try the above approach.

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





In this approach it will be modifying complete data set right? I want this condition only for one report and i will be creating the parameters in data model.

rajendraongole1
Super User
Super User

Hi @PavaniD -you can achieve the date filtering logic similar to your SQL query in Power BI using parameters and Power Query Editor.

Create two parameters in Power BI, one for PARAM1 and another for PARAM2. Make sure to set the data type of these parameters to Date/Time and configure the default values as required.

In your power query editor, below steps should be added 
Param1 = DateTime.FromText(Text.From(Date.From(DateTime.LocalNow())),
Param2 = DateTime.FromText(Text.From(Date.From(DateTime.LocalNow()))),
FilteredRows = Table.SelectRows(Source, each ([CRE_DTTM] >= if [CRE_DTTM] = Param1 then Date.AddDays(DateTime.LocalNow(), -90) else Param1
and [CRE_DTTM] <= if [CRE_DTTM] = Param2 then Date.AddDays(DateTime.LocalNow(), 1) else Param2))

 

This script will filter the rows based on the parameters PARAM1 and PARAM2. It compares the values of [CRE_DTTM] with the parameters and applies the filtering logic accordingly.

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.