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

Dynamically filter the contents of a matrix in specific conditions

DatedateKeyFiscal Year
29/9/2022202209292022
30/9/2022202209302022
01/10/2022202210012023
02/10/2022202210022023

 

I have a 'before' date slicer using the date above, linked to my fact table on the dateKey.

 

Sample Fact table:

CodeNumberdateKeyFiscalYearvalueFlagFor350Code
299202110012022750
2992022092920221000
2992022100120231200
3502021092920211401
3502022092920225001
3502022100120235501
400202109292021500
400202209292022600
400202209302022450
400202210012023650

 

In my matrix, I want to see everything up to that point/date (summed up), for each codeNumber, except for codenumber values of 350, in which case I only want the sum of the values which fall within the max fiscal year as selected in the date slicer.

 

eg. 

on 'to date' 01/10/2022 (ie fiscal year 2023):

codeNumbertotal
29975+100+120 = 295
350550 only
40050+60+45+65 = 220

 

on 'to date' 30/09/2022(ie fiscal year 2022): 

codeNumbertotal
29975+100 = 275
350500 only
40050+60+45 = 155

 

A calculated table doesn't work, since once loaded, it doesn't reload the calculations:

 

Table =
VAR _AsOfFiscalYear = CALCULATE(MAX('dwh DimDate'[FiscalYearNumerical]), ALL('dwh DimDate'))
RETURN
Filter('factTable',IF('factTable'[FlagFor350Code] = 1,'factTable'[FiscalYear] = _AsOfFiscalYear, TRUE()))
 
I've tried a number of measures, to no avail:
eg. 
Measure 4 =
VAR _AsOfFiscalYear = CALCULATE(MAX('dwh DimDate'[FiscalYearNumerical]), ALL('dwh DimDate'))

RETURN IF(AVERAGE('factTable'[FlagFor350Code]) = 0,1, if(AVERAGE('factTable'[FlagFor350Code]) = 1 && AVERAGE('factTable'[FiscalYear]) = _AsOfFiscalYear, 1,0))
 
Then I tried to filter the visual by measure 4 = 1.
 
I've simplified the issue a little, but it needs to be a matrix, and there are a range of codes which need to be excluded except for the max fiscalYear in addition to 350. 
 Can anyone help?
4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hey @Ashish_Mathur  - the link is not working

File attached here.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
DataInsights
Super User
Super User

@Anonymous,

 

Try these measures:

 

Total Value = SUM ( FactTable[value] )
Total Measure = 
VAR vMaxFiscalYear =
    MAXX ( ALLSELECTED ( DimDate ), DimDate[Fiscal Year] )
VAR vTable =
    ADDCOLUMNS (
        VALUES ( FactTable[CodeNumber] ),
        "@Amount",
            VAR vCode350Amount =
                CALCULATE (
                    [Total Value],
                    FactTable[FlagFor350Code] = 1,
                    DimDate[Fiscal Year] = vMaxFiscalYear
                )
            RETURN
                IF ( FactTable[CodeNumber] = 350, vCode350Amount, [Total Value] )
    )
VAR vResult =
    SUMX ( vTable, [@Amount] )
RETURN
    vResult

 

DataInsights_0-1676140989370.png

 

---

 

DataInsights_1-1676141009332.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.