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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

SQL function like behavior using DAX

This may have already been addressed, however, I am still working on my DAX education so I’m sure I just don’t understand enough to realize I passed over the information. Thanks in advance for any help possible.

 

I have a MS SQL query that utilizes a function that requires start date and end date parameters. The way the function works is essentially when specific dates run within the date range the data will be flagged as either current, prior or future. Below are the criteria for each flag:

  • Current – If the ShipDate and QuoteDate is between Monday (first day of our week) of this week and Sunday (last day of our week).
  • Prior – If the ShipDate is between Monday and Sunday of this week and the QuoteDate is prior to the Monday of this week.
  • Future – If the ShipDate is after the Sunday of this week and the QuoteDate is between Monday and Sunday of this week.

My report is utilizing the Date Slicer to create the Date Range for several other pages, however, I cannot seem to figure out how to duplicate the behavior of the function in Power BI and utilize the Date Slicer. Is this possible in Power BI or am I reaching at this point?

1 ACCEPTED SOLUTION

Hi @Anonymous

According to the rule, it seems the line should be "current" instead of "future", 2018/10/21 is the Sunday of this week

ID Ship Date Quote Date Future
20021373QT 10/21/2018 10/19/2018 1

 

when you select a date range (date column from a disconnected table) 

Create measures in the table

min = MIN(calendar[date])

weeknum-Ship Date = WEEKNUM(MAX([Ship Date]),2) weeknum-Quote Date = WEEKNUM(MAX([Quote Date]),2) currentweek = WEEKNUM([min]) state = SWITCH ( TRUE (), [weeknum-Ship Date] = [currentweek] && [weeknum-Quote Date] = [currentweek], "current", [weeknum-Ship Date] = [currentweek] && [weeknum-Quote Date] < [currentweek], "prior", [weeknum-Ship Date] > [currentweek] && [weeknum-Quote Date] = [currentweek], "future" )

7.png

 

 

Best Regards

Maggie

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

I completely forgot to include some data and I apologize for that. However, I should probably also clarify that while the explanation states "this week", the date range may be any date range. The sample data below is from a date range of 10/15/18 - 10/21/18. 

 

Current
IDShip DateQuote DateCurrent
20021334QT10/16/201810/15/20181
20021338QT10/16/201810/15/20181
20021340QT10/16/201810/16/20181
20021341QT10/16/201810/16/20181
20021342QT10/16/201810/16/20181
20021346QT10/17/201810/16/20181
20021347QT10/16/201810/16/20181
20021348QT10/17/201810/17/20181
20021349QT10/15/201810/17/20181
20021350QT10/17/201810/17/20181
    
Prior
IDShip DateQuote DatePrior
20021319QT10/18/201810/11/20181
20021326QT10/15/201810/12/20181
20021327QT10/15/201810/12/20181
20020937QT10/18/20188/30/20181
20021296QT10/16/201810/10/20181
20020376QT10/19/20187/17/20181
20021320QT10/19/201810/12/20181
    
Future
IDShip DateQuote DateFuture
20021373QT10/21/201810/19/20181
20021375QT11/5/201810/19/20181

Hi @Anonymous

According to the rule, it seems the line should be "current" instead of "future", 2018/10/21 is the Sunday of this week

ID Ship Date Quote Date Future
20021373QT 10/21/2018 10/19/2018 1

 

when you select a date range (date column from a disconnected table) 

Create measures in the table

min = MIN(calendar[date])

weeknum-Ship Date = WEEKNUM(MAX([Ship Date]),2) weeknum-Quote Date = WEEKNUM(MAX([Quote Date]),2) currentweek = WEEKNUM([min]) state = SWITCH ( TRUE (), [weeknum-Ship Date] = [currentweek] && [weeknum-Quote Date] = [currentweek], "current", [weeknum-Ship Date] = [currentweek] && [weeknum-Quote Date] < [currentweek], "prior", [weeknum-Ship Date] > [currentweek] && [weeknum-Quote Date] = [currentweek], "future" )

7.png

 

 

Best Regards

Maggie

Greg_Deckler
Community Champion
Community Champion

Can you provide sample data? Do you have a Calendar table? You can use WEEKDAY and WEEKNUM and TODAY to figure out most of the base data that you will need to recreate this in DAX but hard to provide specific instructions without knowing your data. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.