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
Johnsnowlife
Helper III
Helper III

Show Change between Min and max Dates

I am trying to show the change in the [% of Fund] for each instrument in the portfolio from the earliest date in the filter period to the latest date in the filter period. So far I have

Change% = 
VAR MaxDate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
VAR MinDate =
    CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
RETURN
    CALCULATE (
        SUMX ( DataAllFunds, DataAllFunds[% of Fund] ),
        DataAllFunds[Date] = MaxDate
    ) - CALCULATE(
		SumX ( DataAllFunds ,DataAllFunds[% of Fund]), DataAllFunds[Date] = MinDate)

Plotting Instrument against %Change gives me the correct values.

 Instrument vs %Change.JPG

But I want to add the change Column into my table which currently shows the holding for the Latest Date in the table and only the instruments classified as "Equity". Then my %Change becomes zero for everything.  

Instrument vs Current Holding vs Change.JPG

Where am I going wrong? 

1 ACCEPTED SOLUTION
Eric_Zhang
Employee
Employee

@Johnsnowlife

It is the filter that affects the expected output. Try to add ALLEXCEPT to your measure. If it doesn't work, please upload a sample pbix file.

 

Change% =
VAR MaxDate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
VAR MinDate =
    CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
RETURN
    CALCULATE (
        SUMX (
            ALLEXCEPT ( DataAllFunds, DataAllFunds[InstrCode] ),
            DataAllFunds[% of Fund]
        ),
        DataAllFunds[Date] = MaxDate
    )
        - CALCULATE (
            SUMX (
                ALLEXCEPT ( DataAllFunds, DataAllFunds[InstrCode] ),
                DataAllFunds[% of Fund]
            ),
            DataAllFunds[Date] = MinDate
        )

View solution in original post

2 REPLIES 2
Eric_Zhang
Employee
Employee

@Johnsnowlife

It is the filter that affects the expected output. Try to add ALLEXCEPT to your measure. If it doesn't work, please upload a sample pbix file.

 

Change% =
VAR MaxDate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
VAR MinDate =
    CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
RETURN
    CALCULATE (
        SUMX (
            ALLEXCEPT ( DataAllFunds, DataAllFunds[InstrCode] ),
            DataAllFunds[% of Fund]
        ),
        DataAllFunds[Date] = MaxDate
    )
        - CALCULATE (
            SUMX (
                ALLEXCEPT ( DataAllFunds, DataAllFunds[InstrCode] ),
                DataAllFunds[% of Fund]
            ),
            DataAllFunds[Date] = MinDate
        )

Thanks Eric! This is what I ended with.

 

Change%M = 
VAR MaxDate =
    CALCULATE ( MAX ( 'DataAllFunds'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
VAR MinDate =
    CALCULATE ( MIN ( 'DataAllFunds'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
RETURN
    CALCULATE (
        SUMX ( DataAllFunds, [Fund % M] ),
        DataAllFunds[Date] = MaxDate
    ) - CALCULATE(
		SumX ( DataAllFunds ,[Fund % M]), DataAllFunds[Date] = MinDate)

 

 

Where Fund % M is 

Fund % M = 
VAR Fund =
    DISTINCT ( DataAllFunds[Fund] )
VAR TDate =
    MAX ( DataAllFunds[Date] )
RETURN
    DIVIDE (
        CALCULATE (
            SUM ( DataAllFunds[Market Value] ),
            DataAllFunds[Fund] = Fund,
            DataAllFunds[Date] = TDate
        ),
        CALCULATE (
            SUM ( DataAllFunds[Market Value] ),
            FILTER (
                ALL ( DataAllFunds ),
                DataAllFunds[Fund] = Fund
                    && DataAllFunds[Date] = TDate
            )
        ),
        0
    )
        * 100

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.