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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
DDL1976
Frequent Visitor

DAX Filter Problem

I am new to the wqorld of DAX and Power BI...

 

I have created the following 2 measures but they dont work...

CFY = LOOKUPVALUE(DimPeriod[Financial Year], DimPeriod[Period End Date], LASTDATE(DimPeriod[Period End Date]))
AC = CALCULATE(SUM(FactTransactionLine[Value]), FILTER(DimPeriod, DimPeriod[Financial Year] = [CFY]))
I don't get an error however the result is the same as if there is no filter.
 
But this measure work perfectly
AC = CALCULATE(SUM(FactTransactionLine[Value]), FILTER(DimPeriod, DimPeriod[Financial Year] = "2020/21"))
I have checked that my CFY easure returns 2020/21 by adding it to a table visual...
 
Any help would be awesome!
1 ACCEPTED SOLUTION
AntrikshSharma
Community Champion
Community Champion

@DDL1976 The former isn't working due to a mechanism know as "Context Transition", pretty sophisticated thing but you will get a hang of it soon.

For now write your code like this:

AC =
VAR CurrentFinancialYear = [CFY]
VAR DateFilter =
    FILTER ( DimPeriod, DimPeriod[Financial Year] = CurrentFinancialYear )
VAR Result =
    CALCULATE ( SUM ( FactTransactionLine[Value] ), DateFilter )
RETURN
    Result

And once you are comfortable with DAX write it like this:

AC =
VAR CurrentFinancialYear = [CFY]
VAR Result =
    CALCULATE (
        SUM ( FactTransactionLine[Value] ),
        KEEPFILTERS ( DimPeriod[Financial Year] = CurrentFinancialYear )
    )
RETURN
    Result

 

View solution in original post

2 REPLIES 2
DDL1976
Frequent Visitor

Thats amazing thank you!

AntrikshSharma
Community Champion
Community Champion

@DDL1976 The former isn't working due to a mechanism know as "Context Transition", pretty sophisticated thing but you will get a hang of it soon.

For now write your code like this:

AC =
VAR CurrentFinancialYear = [CFY]
VAR DateFilter =
    FILTER ( DimPeriod, DimPeriod[Financial Year] = CurrentFinancialYear )
VAR Result =
    CALCULATE ( SUM ( FactTransactionLine[Value] ), DateFilter )
RETURN
    Result

And once you are comfortable with DAX write it like this:

AC =
VAR CurrentFinancialYear = [CFY]
VAR Result =
    CALCULATE (
        SUM ( FactTransactionLine[Value] ),
        KEEPFILTERS ( DimPeriod[Financial Year] = CurrentFinancialYear )
    )
RETURN
    Result

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Power BI Header Change

Power BI Header Update

Read about the exciting updates for the Power BI forum.

Top Solution Authors