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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Martin_R
Frequent Visitor

Why is this DAX query returning all product categories ?

Hi,

I have the following query that is returning all categories when it should only return category "Audio". I have 3 filters on the CALCULATE and they all work except 'Product Category'[Category] = "Audio"

 

EVALUATE
VAR SelectedYears = 
    CALCULATE(
        DISTINCTCOUNT('Date'[Calendar Year]),
        CROSSFILTER(Receipts[SaleDateKey], 'Date'[DateKey], BOTH),
        DATESBETWEEN(Receipts[Sale Date], DATE(2007, 1, 1), DATE(2009, 12, 31)),     
        ALLSELECTED()
    )
VAR StatusGranularity =
    SUMMARIZE (
        Receipts,
        Store[Store Name],
        'Product Category'[Category]
    )
VAR OpenStores =
    FILTER (
        StatusGranularity,
        VAR YearsWithSales = 
        CALCULATE(
            DISTINCTCOUNT('Date'[Calendar Year]),
            store[CountryRegion] = "Germany",
            'Product Category'[Category] = "Audio",
            store[Store Type] = "Store",            
            CROSSFILTER(Receipts[SaleDateKey], 'Date'[DateKey], BOTH),        
            ALLSELECTED('Date'[Calendar Year])
        )
        RETURN
        YearsWithSales = SelectedYears            
    )
RETURN 
    OpenStores

 

This is the result

Martin_R_0-1705629820322.png

https://drive.google.com/file/d/1hyUnvnjfDDqjZ7zQykD2Ij6vtBcH2KvM/view?usp=drive_link

1 ACCEPTED SOLUTION

pls try this

Screenshot_2.png

 

EVALUATE
VAR SelectedYears = 
    CALCULATE(
        DISTINCTCOUNT('Date'[Calendar Year]),
        CROSSFILTER(Receipts[SaleDateKey], 'Date'[DateKey], BOTH),
        DATESBETWEEN(Receipts[Sale Date], DATE(2007, 1, 1), DATE(2009, 12, 31)),     
        ALLSELECTED()
    )
VAR StatusGranularity =
    FILTER(SUMMARIZE (ALL(
        Receipts),
        Store[Store Name],
        'Product Category'[Category]
    ),'Product Category'[Category] = "Audio")
VAR OpenStores =
    FILTER (
        StatusGranularity,
        VAR YearsWithSales = 
        CALCULATE(
            DISTINCTCOUNT('Date'[Calendar Year]),
            store[CountryRegion] = "Germany",
            store[Store Type] = "Store",            
            CROSSFILTER(Receipts[SaleDateKey], 'Date'[DateKey], BOTH),        
            ALLSELECTED('Date'[Calendar Year])
        )

 

View solution in original post

4 REPLIES 4
Martin_R
Frequent Visitor

That should work now

pls try this

Screenshot_2.png

 

EVALUATE
VAR SelectedYears = 
    CALCULATE(
        DISTINCTCOUNT('Date'[Calendar Year]),
        CROSSFILTER(Receipts[SaleDateKey], 'Date'[DateKey], BOTH),
        DATESBETWEEN(Receipts[Sale Date], DATE(2007, 1, 1), DATE(2009, 12, 31)),     
        ALLSELECTED()
    )
VAR StatusGranularity =
    FILTER(SUMMARIZE (ALL(
        Receipts),
        Store[Store Name],
        'Product Category'[Category]
    ),'Product Category'[Category] = "Audio")
VAR OpenStores =
    FILTER (
        StatusGranularity,
        VAR YearsWithSales = 
        CALCULATE(
            DISTINCTCOUNT('Date'[Calendar Year]),
            store[CountryRegion] = "Germany",
            store[Store Type] = "Store",            
            CROSSFILTER(Receipts[SaleDateKey], 'Date'[DateKey], BOTH),        
            ALLSELECTED('Date'[Calendar Year])
        )

 

Thanks,


I still dont understand why I cant filter StatusGranularity on 'Product Category'[Category] = "Audio". StatusGranularity should preserve data lineage on on 'Product Category'[Category], The other filters for Columns from Store work.

Ahmedx
Super User
Super User

No access to file

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.