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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

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, @Anonymous ;

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, @Anonymous ;

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.

Anonymous
Not applicable

Hello @Anonymous 

 

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 @Anonymous 
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

 

 

Anonymous
Not applicable

SankeyThakkar_7_0-1647430403168.png

 

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

Hi @Anonymous 
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

@Anonymous 
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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Anonymous
Not applicable

@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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Anonymous
Not applicable

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>

 

Anonymous
Not applicable

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 )



Anonymous
Not applicable

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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