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
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
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.