cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SankeyThakkar_7
Helper II
Helper II

Help in time related DAX

Hey Experts,

 

I need help with dax.

 

I have two columns one is SALE DATE and one is ORDER DATE. I need one column or measure according below condition,
Ever order date has multiple sale date.
My sale date always should be last thursday of month. so whatever order date is there whichever coming sale date is "current" for me and otherones are "Next" for me.

example:

Order dateSale dateExp(REQUIRED MEASURE)
16/03/2022|||31/03/2022(last thursday of march)|||Current
16/03/2022|||28/04/2022(last thursday of april)|||Next
22/04/2022|||28/04/2022(last thursday of april)|||Current
22/04/2022|||26/05/2022(last thursday of may)|||Next
22/04/2022|||30/06/2022(last thursday of jun)|||Next
29/04/2022|||26/05/2022(last thursday of may)|||Current
29/04/2022|||30/06/2022(last thursday of jun)|||Next
   


I hope uou clear withrequirment. I want EXP as measure.

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @SankeyThakkar_7 ;

Try it.

result = 
VAR _min =
    CALCULATE ( MIN ( Data[Sale date] ),FILTER(ALLSELECTED('Data'),[Order date]=MAX([Order date])))
RETURN
    IF (
        MAX(  Data[Sale date] ) = _min,
        "Current",
        "Next")

The final output is shown below:

vyalanwumsft_0-1647842686534.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

12 REPLIES 12
v-yalanwu-msft
Community Support
Community Support

Hi, @SankeyThakkar_7 ;

Try it.

result = 
VAR _min =
    CALCULATE ( MIN ( Data[Sale date] ),FILTER(ALLSELECTED('Data'),[Order date]=MAX([Order date])))
RETURN
    IF (
        MAX(  Data[Sale date] ) = _min,
        "Current",
        "Next")

The final output is shown below:

vyalanwumsft_0-1647842686534.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

shwetadalal
Resolver II
Resolver II

Hello @SankeyThakkar_7 

 

First make a Date dimension table (Date = CALENDARAUTO()) and make following relationship between 'Order Date' and 'Date':

shwetadalal_0-1647435280610.png

After that use following measure:

Measure =
VAR startdate =
DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Order Date] ) ), MONTH ( SELECTEDVALUE ( 'Table'[Order Date] ) ), 1 )
VAR enddate =
DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Order Date] ) ), MONTH ( SELECTEDVALUE ( 'Table'[Order Date] ) ) + 1, 1 ) - 1
VAR maxthursday =
CALCULATE (
MAX ( 'Date'[Date] ),
FILTER (
ALL ( 'Date' ),
'Date'[Date] >= startdate
&& 'Date'[Date] <= enddate
&& FORMAT ( 'Date'[Date], "dddd" ) = "Thursday"
)
)
VAR conditionCurrentNext =
IF (
( maxthursday = SELECTEDVALUE ( 'Table'[Sale Date] ) ),
"Current",
IF (
(
SELECTEDVALUE ( 'Table'[Sale Date] ) > maxthursday
&& SELECTEDVALUE ( 'Table'[Order Date] ) < maxthursday
),
"Next",
IF (
(
SELECTEDVALUE ( 'Table'[Order Date] ) > maxthursday
&& DATEDIFF (
SELECTEDVALUE ( 'Table'[Order Date] ),
SELECTEDVALUE ( 'Table'[Sale Date] ),
DAY
) > 31
),
"Next",
"Current"
)
)
)
RETURN
conditionCurrentNext
 
The output I got with this measure matched your requirement:
shwetadalal_1-1647435438370.png

 

 

Please accept it as a solution if it matches your requirement🙂

 

tamerj1
Super User
Super User

Hi @SankeyThakkar_7 
You can try this calculated column

 

 

Distribution Column: =
VAR CurrentSaleDate = Data[exp]
VAR CurrentOrderDateTable =
    CALCULATETABLE ( Sheet1, ALLEXCEPT ( Sheet1, Sheet1[Date] ) )
VAR NumberOfSales =
    COUNTROWS ( CurrentOrderDateTable )
VAR FirstSaleDate =
    MINX ( CurrentOrderDateTable, Sheet1[exp] )
VAR Result =
    IF (
        NumberOfSales = 1,
        "Current",
        IF ( CurrentSaleDate = FirstSaleDate, "Current", "Next" )
    )
RETURN
    Result

 

 

SankeyThakkar_7_0-1647430403168.png

 

Measure working fine after adding filter value. But calculated column giving not proper result.

Hi @SankeyThakkar_7 
Would you please double check the code you're using as it works in sample file https://www.dropbox.com/t/yGBAowmIe1PHgg7b
1.png2.png

@SankeyThakkar_7 
Also I believe that the solution provide by @Jihwan_Kim should work with no issues. Is there any chance that we are missing something here?

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Expected result measure: =
VAR currentorderdate =
    MAX ( Data[Order date] )
VAR commingsalesdate =
    CALCULATE ( MIN ( Data[Sale date] ), ALLEXCEPT ( Data, Data[Order date] ) )
VAR result =
    IF (
        SELECTEDVALUE ( Data[Order date] ) = currentorderdate
            && SELECTEDVALUE ( Data[Sale date] ) = commingsalesdate,
        "Current",
        "Next"
    )
RETURN
    IF ( HASONEVALUE ( Data[Order date] ), result )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


@Jihwan_Kim not working sir

 

Please share your sample.

I think the sample that is described in your question is different than what you show in the reply.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Sorry sir. Its my mistake. I applied some filter on page if i mention that filter in mymeasure its working fine. but my question is if i add more filter in future it automatically make my measure wrong. any solution for that sir>

 

SankeyThakkar_7_0-1647418284427.png

Not Working in my case.

Distribution2 =
VAR currentdate =
MAX ( Sheet1[Date] )
VAR commingexpdate =
CALCULATE ( MIN ( Sheet1[Exp] ), ALLEXCEPT ( Sheet1, Sheet1[Date] ) )
VAR result =
IF (
SELECTEDVALUE ( Sheet1[Date] ) = currentdate
&& SELECTEDVALUE ( Sheet1[Exp] ) = commingexpdate,
"Current",
"Next"
)
RETURN
IF ( HASONEVALUE ( Sheet1[Date] ), result )



SankeyThakkar_7
Helper II
Helper II

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors