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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Arydperez
Frequent Visitor

ISSUE FILTERING DATES IN CALCULATED COLUMN

There are 1 Fact Table and one linked Date Table (marked as Date Table). The link is a Single One in Date Table to Many in Fact Table.

I created a Calculated Column in the Fact Table that SHOULD show value 1 to the row that has the last Date (filtered by the slicer Date from the Date Table).

The problem is that the expression from the calculated column is always bringing the value 1  for the last date row of the group, REGARDLESS the value of the slicer. (I am attaching the PBIX):

Calculated Column expresson: 

last_date PRODUCT_WHS =
IF (
'FACT TABLE'[DATE]
= CALCULATE (
MAX ( ('FACT TABLE'[DATE] )),
ALLEXCEPT(
'FACT TABLE',
'FACT TABLE'[PRODUCT],
'FACT TABLE'[WHS]
), 1)

Work for the whole range of dates:

Arydperez_0-1661532237283.png

 

Result is wrong when the slicer exclude the last date

Arydperez_1-1661532665279.png

 

Appreciate any idea to solve the Dax  Expression to make what it is suppose to do.

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Arydperez 
You are are right it is simple but tricky at the same time. The thing that we did not consider in the comparison that Blank = Blank this is why the results kept populating 1 despite of the filter context. Please use the following and refer to the attached sample file.

1.png2.png3.png

last_date PRODUCT_WHS = 
VAR CurrentDate = MAX ( 'FACT TABLE'[DATE] )
VAR MaxtDate = 
    CALCULATE (
        MAX ( 'FACT TABLE'[DATE] ),
        REMOVEFILTERS ( 'FACT TABLE' ),
        VALUES ( 'FACT TABLE'[PRODUCT] ),
        VALUES ( 'FACT TABLE'[WHS] ),
        VALUES ( 'DATE TABLE'[Date] )
    )
VAR Result =
    IF ( NOT ISBLANK ( CurrentDate ) && CurrentDate = MaxtDate, 1 )
RETURN
    Result

 

View solution in original post

6 REPLIES 6
tamerj1
Super User
Super User

Hi @Arydperez 
You are are right it is simple but tricky at the same time. The thing that we did not consider in the comparison that Blank = Blank this is why the results kept populating 1 despite of the filter context. Please use the following and refer to the attached sample file.

1.png2.png3.png

last_date PRODUCT_WHS = 
VAR CurrentDate = MAX ( 'FACT TABLE'[DATE] )
VAR MaxtDate = 
    CALCULATE (
        MAX ( 'FACT TABLE'[DATE] ),
        REMOVEFILTERS ( 'FACT TABLE' ),
        VALUES ( 'FACT TABLE'[PRODUCT] ),
        VALUES ( 'FACT TABLE'[WHS] ),
        VALUES ( 'DATE TABLE'[Date] )
    )
VAR Result =
    IF ( NOT ISBLANK ( CurrentDate ) && CurrentDate = MaxtDate, 1 )
RETURN
    Result

 

Arydperez
Frequent Visitor

Hi Tamer,

Thank you vm for the idea. Unfortunately it didn't work.  It brings only '0' and also, interestingly, brings the whole set of dates, regardless the slicer Date values. Result below.

Arydperez_0-1661542685966.png

 

 

 

@Arydperez 

Please try

last_date PRODUCT_WHS =
IF (
    MAX ( 'FACT TABLE'[DATE] )
        = CALCULATE (
            MAX ( 'FACT TABLE'[DATE] ),
            ALLSELECTED ( 'FACT TABLE'[Date] ),
            ALL ( 'FACT TABLE'[Value] )
        ),
    1
)

Hi,

It is much better!! Thanks! The problem is that it is still bringining all the data of the Fact Table even slicing it for a period it should leave records outside the view but also the values do not match.  If there is a way to share the pbix I could leave it. It is a very simple report.

Arydperez_1-1661554772861.png

 

 

 

Hi @Arydperez 

you can upload to onedrive, dropbox, WeTransfer or any similar cloud service and share the link in a reply. 

tamerj1
Super User
Super User

Hi @Arydperez 

a calculated shall work as it does not react dynamically with filter context. You have to add it as a measure 

 

last_date PRODUCT_WHS =
IF (
    MAX ( 'FACT TABLE'[DATE] )
        = CALCULATE (
            MAX ( 'FACT TABLE'[DATE] ),
            ALLEXCEPT ( 'FACT TABLE', 'FACT TABLE'[PRODUCT], 'FACT TABLE'[WHS] )
        ),
    1,
    0
)

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Kudoed Authors