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
EFGPFS
Frequent Visitor

Values based on max date of slicer

I am trying to get the value for the max date based on the slicer. Below is an explanation of what I am trying to do:

 

Here is my starting data:

FundDateValue
112/21/2021100
13/15/2022150
14/16/202250
211/14/2021200
21/16/2022150
22/16/2022200
310/8/2021300
31/15/202150
33/18/2022150

 

I want the data to show only the values for the max date selected by slicer and the rest of the values to be 0.

 

So if I choose a slicer with a max date of 3/31/2022, the following would be the output:

FundDateValue
112/21/20210
13/15/2022150
14/16/20220
211/14/20210
21/16/20220
22/16/2022200
310/8/20210
31/15/20210
33/18/2022150

 

Or if I choose a slicer with a max date of 2/18/2022, the following would be the output:

FundDateValue
112/21/2021100
13/15/20220
14/16/20220
211/14/20210
21/16/20220
22/16/2022200
310/8/20210
31/15/202150
33/18/20220

 

I have tried the following function but it always chooses the max date of the entire data set and not the slicer.

 

 

 

Terminal Value Date = IF('Data'[Date]=MAXX(allselected('Data'),'Data'[Date]),'Data'[Value],0)

 

 

 

 

I have tried searching onlinethe past couple of days and I can't seem to find a solution that works. Any advise will be much appreciated. Thanks!

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

I don't need a calculated column at all,

CNENFRNL_0-1654552514773.png

CNENFRNL_2-1654552747612.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

8 REPLIES 8
CNENFRNL
Community Champion
Community Champion

CNENFRNL_3-1654541656771.png

 

For fun only, a showcase of powerful Excel worksheet formula; MAXIFS() is better if available in your Excel,

CNENFRNL_2-1654541121498.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thanks! What is the Total in your measure?

 

EFGPFS_0-1654543320986.png

 

 

 

EFGPFS
Frequent Visitor

@CNENFRNL 

 

Sorry I didn't see the download at first. I tried your method but get the following error for value retained:

 

"All arguments within an ALLEXCEPT function must be related to (or contained by) the table which is used as the first argument. Where a one-to-many relationship exists, the table which is used as the first argument must be on the 'many' side of that relationship."

 

The "Value" I am using in my example is a calculated column of a running total, and seems to throw an error in the solution you suggested. See below.

 

 

Value = 
    CALCULATE(
        SUM('Data'[Transaction Amount]),
        FILTER(
            'Data',
            'Data'[Fund]=EARLIER('Data'[Fund])
            && 'Data'[Date] <= EARLIER('Data'[Date])
            )
            )

 

 

 

So my data looks like this:

FundDateTransaction Amount Value
112/21/2021100100
13/15/202250150
14/16/2022(100)50
211/14/2021200200
21/16/2022(50)150
22/16/202250200
31/15/20215050
310/8/2021250300
33/18/2022(100)150

Do you have any suggestions for how to deal with the error? Any help is greatly appreaciated. Thanks!

CNENFRNL
Community Champion
Community Champion

I don't need a calculated column at all,

CNENFRNL_0-1654552514773.png

CNENFRNL_2-1654552747612.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL Thanks, I really apperciate your help. This solution kind of works, however, I am ultimatly trying to calculate an XIRR of the Accum field plus a cashflow field. 

 

So if I choose a data of 2/18/2022, the data would appear as the folowing:

FundDate Cashflow 

Transaction

Amount 

Accum

Cashflow +

Accum

112/21/2021(10.00)10010090.00
13/15/2022(30.00)5000
14/16/2022(40.00)-10000
211/14/2021(50.00)2000(50.00)
21/16/202210.00-50010.00
22/16/2022(20.00)50200180.00
31/15/2021(30.00)500(30.00)
310/8/2021(60.00)250300240.00
33/18/202220.00-10000

 

I am able to get a table that looks like the above, however, the XIRR of the Cashflow + Accum is not calculating correctly.

 

To calculate Cashflow + Accum I use the following measure:

 

 

 

Cashflow + Accum = sum('Data'[Cashflow])+_Measures[Accum]

 

 

 

 

Then I use the following measure to calculate the XIRR:

 

 

 

XIRR = 
VAR Summary =
    SUMMARIZE ( 'Data', 'Data'[Date], "@Amt", _Measures[Cashflow + Accum])
VAR FilterZeros =
    FILTER ( Summary, [@Amt] <> 0 )
RETURN
    XIRR ( FilterZeros, [@Amt], 'Data'[Date] )

 

 

 

 

I think the XIRR isn't calculating correctly beacuse the Cashflow + Accum is a measure and not calculated column. Do you have any suggestions on how to get the XIRR to work?  Note the data is made up and the XIRR may not converge in the example I have given.

 

Any help would be greatly appreaciated.

SpartaBI
Community Champion
Community Champion

@EFGPFS I created an example with your data:
MaxDate.pbix

2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

@SpartaBI  Thanks, that isn't quite what I am looking for but I really appreciate your effort. For each fund there should only be one value based on the max date and the rest would be 0. Your solution shows all values less than the max date. I only want the value for the most max date less than the slicer date. In the tables below I highlighted the differences.

 

So for example if I choose 2/18/2022 in your workbook I get the following results:

FundDateValue
112/21/2021100
13/15/20220
14/16/20220
211/14/2021200
21/16/2022150
22/16/2022200
310/8/2021300
31/15/202150
33/18/20220

 

When what I am looking for is the following results when I set the slicer to 2/18/2022:

FundDateValue
112/21/2021100
13/15/20220
14/16/20220
211/14/20210
21/16/20220
22/16/2022200
310/8/20210
31/15/202150
33/18/20220

 

Please respond if you have any more thoughts on the problem. Again I appreciate any help!!

SpartaBI
Community Champion
Community Champion

@EFGPFS change the measure in my file to:

 

Measure Result = 
VAR _current_date = MAX('Table'[Date])
VAR _max_selected_date = MAX('Calendar'[Date])
VAR _max_date_per_fund_before_max_selected_data = 
    CALCULATE(
        MAX('Table'[Date]), 
        REMOVEFILTERS('Table'),
        VALUES('Table'[Fund]),
        'Table'[Date] < _max_selected_date 
        )
VAR _result = 
    IF(_current_date <= _max_date_per_fund_before_max_selected_data,  SUM('Table'[Value]), 0)
RETURN
    _result

 

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.