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
Anonymous
Not applicable

DAX filter calculated table based on another table

Hello,

 

Please assist me with this DAX measure I'm trying to calculate the sum of inventory based on the countries for a selected user.

I have attached my pbix file with the measure  called "TotalInventoryProcessedForSelectedUserCountries"

I'm trying to get the total for all users which had the same countries with inventory as Ann where from 25 April to 1 May 2020 Ann had inventory in 6 countries (Brazil,Canada,Ireland,Mexico,US and Venezuela). I need the total inventory for all users who had inventory in those same 6 countries. My measure now returns all users and all countries but I need only the selected user's countries.  

 

PBIX file link - https://www.dropbox.com/s/5rxhb0ajieqwzyj/TableFilter.pbix?dl=0

 

My DAX code :=

TotalInventoryProcessedForSelectedUserCountries =
VAR FirstDateSelected = MIN('DimDates'[Date])
var LastDateSelected = MAX('DimDates'[Date])

VAR Result =
CALCULATETABLE(
FILTER(
ADDCOLUMNS(
SUMMARIZE(
'data',
data[User Name],
'data'[Country]
),
"@InventoryProcessed",[SumOfInventoryProcessed]

)
,[@InventoryProcessed]>0
),
FILTER(ALL('DimDates'),
'DimDates'[Date] >= FirstDateSelected &&
'DimDates'[Date] <= LastDateSelected
)
,ALL('data'[Country])
,ALL( data[User Name])
)

RETURN
SUMX(Result,[@InventoryProcessed])



 

 

Untitled.png

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @Anonymous ,

 

I think I found an easier way.

First I get the countries for the current user and then I just use that list as a filter for calculate.

 

Check the following approach:

TotInventory =
-- Get all countries for the current user
VAR vCountries =
    CALCULATETABLE(
        VALUES( data[Country] ),
        ALLEXCEPT(
            data,
            data[User Name]
        )
    )
RETURN
    -- return the [SumOfInventoryProcessed] and we use
    -- as only filter the countries from the first step
    CALCULATE(
        [SumOfInventoryProcessed],
        vCountries,
        ALL( data )
    )

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thank you it worked 🙂

selimovd
Super User
Super User

Hey @Anonymous ,

 

I think I found an easier way.

First I get the countries for the current user and then I just use that list as a filter for calculate.

 

Check the following approach:

TotInventory =
-- Get all countries for the current user
VAR vCountries =
    CALCULATETABLE(
        VALUES( data[Country] ),
        ALLEXCEPT(
            data,
            data[User Name]
        )
    )
RETURN
    -- return the [SumOfInventoryProcessed] and we use
    -- as only filter the countries from the first step
    CALCULATE(
        [SumOfInventoryProcessed],
        vCountries,
        ALL( data )
    )

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

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.

Top Solution Authors