Dax Compare Dates

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

 Posted Aug 26, 2018 09:23 AM

Reply Reply Privately Options Dropdown

Hi ALL,

How to compare two date values in power bi.


1.parameter date (its like measure date)
2. another one is calculate date column

How can I compare with measure and calculated date.

Intervalstartdate : Interval Start Date(meausre date) =


IF(HASONEVALUE(Dates[Date]),VALUES(Dates[Date]))
Start_date  : Source date (calculated date)

need to compare with both filed like : IF(interval start date >
start_date ,max(interval start date ),min(start date))
------------------------------
NS
------------------------------

 2.  RE: How to compare Parameter date and calculated date in


Powerbi(DAX)

0    Recommend
Silver Contributor

Andrew Seward

Posted Aug 27, 2018 10:21 AM

Reply Options Dropdown


Reply Privately

Can you share a bit more about the data tables and relationships
and what your trying to accomplish. I think your
overcomplicating things a bit by doing what PBI will do implicitly
for you and may not be using the date table in the best way.

It looks like your filtering your Date Table directly by your slicers.
This will limit any related tables to that single date (is this what
you want?)

For getting user input I typically collect via Disconnected Tables


with slicers. In your case I would create 3 disconnected tables
Years = VALUES(Date[Year Number])
Months = VALUES(Date[Month Number]
Days = VALUES(Date[Day Number]

Then a Measure to Harvest the values selected


Selected Year = SELECTEDVALUE(Years[Year
Number],YEAR(TODAY)) //Default to current year
Selected Month = SELECTEDVALUE(Months[Month
Number],MONTH(TODAY())
Selected Day = SELECTEDVALUE(Days[Day
Number],DAY(TODAY())

And a Measure to Calculate the Selected Date


Selected Date = DATE([Selected Year],[Selected Month],[Selected
Day])

I'm not sure how your FACT Table is Related to Your Date Table

But if you have a [Start Date] Measure that works and returns a
Single Date Value then the conditional Date measure you were
asking for is
Conditional Start Date = IF([Selected Date]<[Start Date],[Selected
Date],[Start Date])

If [Start Date] is a column that can return multiple values then


Conditional Start Date = VAR Min_Start_Date = MIN(table[Start
Date] RETURN
IF([Selected Date]<Min_Start_Date,[Selected
Date],Min_Start_Date)

------------------------------
Andrew Seward
Senior Product Marketing Engineer
8454758636
------------------------------

 Original Message

 3.  RE: How to compare Parameter date and calculated date in


Powerbi(DAX)

0    Recommend

Bronze Contributor

sN

Posted Aug 27, 2018 09:56 PM

Reply Reply Privately Options Dropdown


@Andrew Seward  ,Thank you so much for your reply,

Data Table is no relation with fact tables.

Interval_start_date : Interval Start Date =


IF(HASONEVALUE(Dates[Date]),VALUES(Dates[Date])) as
measure
Start_date from fact but its column when I compared column
and measure ,I don't get any values .
This is for parameter when enter the user input(like
year,month,day) then dynamically need to change then
compare with fact column start_date.
Can I store the user input value in table to compare or how
can I compare both dates with if it condition is true  max date
and if it is fail min date.
Could you please help me on this.

I used date diff,IF statement,var but still getting empty values.

Thanks
NS
4252299069

------------------------------
NS
------------------------------

 Original Message

 4.  RE: How to compare Parameter date and calculated date in


Powerbi(DAX)

0    Recommend
Silver Contributor

Daniel Davis

Posted Aug 31, 2018 08:23 AM

Reply Reply Privately Options Dropdown

Put an additional condition in your IF statement to exclude


nulls, and double check your model that there aren't cross
filters somewhere else affecting the filters going into the
measure

------------------------------
Daniel Davis
Business Intelligence Developer
TPX Communications
Portland, ME
------------------------------

 Original Message

You might also like