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
Anonymous
Not applicable

Reading the Date column using Dax

Hi All,

 

I am literally pulling my hair to get the measure right. I have tried different ways and currently stuck. The logic is quite basic but the issue is with reading the date column . Let me elaborate the measure I am looking for.
The shortage column in the below table is a measure and Date is a column coming from the model.  The logic I am looking for is If shortage =1 , planned dates else blank. 
The point that I am stuck at is, As i am trying to build a measure using IF , to read the date column I am using Min or Max functions, which is returning the min or max date instead of returning the 2 dates for particular product and location.
The measure that I have tried.

Planned_Dates =
Var End_ = FILTER(Short_Ship[Beg_Inv]<0 && [Shortage]=1)
Var dt = MinX(End_Plant[Date])
return
IF([Shorts]=1dtBLANK())

 

Planned date =
VAr Dt = SELECTEDVALUE(Plant[Date])
Var Short = [Shortage]
Return
IF(Short=1DtBLANK())    

ProductLocationDateBeg_inv Shortage 
402390122307-10-2022700
402390122308-11-2022-51
402390122308/13/2022250
402390122308/14/2022300
402390122308/15/2022-151
402390122308/17/2022-20
402390122308/18/202270
402390122308/20/2022300
So the actual problem here is, The measure returns the minimum date when I add into a table without a Date column like below.
ProductLocationPlanned Dates
402390122308-11-2022

But When I add the Planned date into a table that already has a date column gives me the right result like below.
ProductLocationDateBeg_inv Shortage  Planned_Dates 
402390122307-10-2022  70   0 
402390122308-11-2022  -5   108-11-2022
402390122308/13/2022   25   0 
402390122308/14/2022   30   0 
402390122308/15/2022  -15   1 08-15-2022 
402390122308/17/2022  -2   0 
402390122308/18/2022   7   0 
402390122308/20/2022   30   0 

I want the Planed date to return the 2 dates though there is no Date column in the table.

Table I am looking for: 
ProductLocationPlanned Dates
402390122308-11-2022
402390122308-15-2022

Hope someone finds a solution for this.

Thnaks in advance.
@tamerj1 @amitchandak @lbendlin @parry2k 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hello agian @Anonymous 
I think the following solution complies more with your requirement. Please refer to attached file

1.png

Place the measure in the filter pane and select "Is not blank" then apply the filter.

Planned_Dates = 
VAR CurrentDate = MAX ( 'Table'[Date] )
VAR T1 = FILTER ( VALUES ( 'Table'[Date] ), [Beg_Inv] < 0 && [Sortage] = 1 )
RETURN
    IF ( CurrentDate IN T1, CurrentDate )

View solution in original post

8 REPLIES 8
tamerj1
Super User
Super User

Hello agian @Anonymous 
I think the following solution complies more with your requirement. Please refer to attached file

1.png

Place the measure in the filter pane and select "Is not blank" then apply the filter.

Planned_Dates = 
VAR CurrentDate = MAX ( 'Table'[Date] )
VAR T1 = FILTER ( VALUES ( 'Table'[Date] ), [Beg_Inv] < 0 && [Sortage] = 1 )
RETURN
    IF ( CurrentDate IN T1, CurrentDate )
tamerj1
Super User
Super User

Hi @Anonymous 
Please cl;arify as below

1.png

*Update

I mean you have two tables.

 

Anonymous
Not applicable

Hi @tamerj1 
Sorry for not Providing the measure in right way.
Forgot to edit the measure properly.

Planned_Dates =
Var End_ = FILTER(Plant[Beg_Inv]<0 && [Shortage]=1)
Var dt = MinX(End_Plant[Date])
return
IF([Shortage]=1dtBLANK())


Apologies again!

 

@Anonymous 

The following shall satisfy this requirement in a different way

Planned_Dates = 
VAR T1 = FILTER ( 'Table', [Beg_Inv] < 0 && [Sortage] = 1 )
RETURN
    CONCATENATEX ( T1, [Date], UNICHAR ( 10 ) )
tamerj1
Super User
Super User

Hi @Anonymous 
I think your problrm id having columns of two dim tables in the same visual . You did not present any information about data model but let me try to guide you through following an example: Let's say the Product ID is comming from the product table (Products[Product ID]) and the fact table date column is Fact[Date] which is filtered by 'Date'[Date] which is the column that you are using in your visual. In this case the DAX to retrieve the date in the current filter context would be
CALCULATE ( MAX ( 'Date'[Date] ), CROSSFILTER ( 'Date'[Date], Fact[Date], BOTH ) )
Or simply 

MAX (  Fact[Date] )

Anonymous
Not applicable

Hi @tamerj1 

Can I know if there is any possibility of creating a calculated column in this case. 
Where in I find trouble in calculating a column including measures in it. There a circualar dependency error popping up every single time I try creating a column.

Anonymous
Not applicable

The entire data i.e. all the columns and measures are coming from the same table which is the fact table.

@Anonymous 
Sorry, I got busy with other business.
I think I did not read properly. Let me check and give it a try

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.