Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Kris48
Frequent Visitor

Assign a maximum value per index

When the 'Index' in the 'Fact' table has a 'data from' later than today's date, then take the last 'value' from the 'Rev' table assigned to that index and multiply this value by the number of days that occur between 'Data from' and 'Data to'

 

Pbix https://drive.google.com/file/d/1BP1IknHOaf8PCym-sLHHkjYeN1g1S6um/view?usp=sharing 

 

1.png

1 ACCEPTED SOLUTION
shafiz_p
Resident Rockstar
Resident Rockstar

Hi @Kris48  Considering you want to achieve, If data from is later than today's date , then take the last value from the rev table assigned to that index and multiply by dates between. Try revise your measure by the code below:

Value_measure = 
VAR CurrentDate = TODAY()
VAR FilteredFact = 
    FILTER(
        'Fact',
        'Fact'[Data from] > CurrentDate
    )
VAR LastRevValue = 
    CALCULATE(
        LASTNONBLANKVALUE('Rev'[Date], SUM('Rev'[Value])),
        TREATAS(VALUES('Fact'[INDEX]), 'Rev'[INDEX])
    )
VAR DaysBetween = 
    SUMX(
        FilteredFact,
        DATEDIFF('Fact'[Data from], 'Fact'[Data to], DAY)+1
    )
RETURN
    LastRevValue * DaysBetween

Output I have :

shafiz_p_0-1730696014590.png

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution and kudos!!

 

Best Regards,

Shahariar Hafiz

View solution in original post

8 REPLIES 8
shafiz_p
Resident Rockstar
Resident Rockstar

Hi @Kris48  Considering you want to achieve, If data from is later than today's date , then take the last value from the rev table assigned to that index and multiply by dates between. Try revise your measure by the code below:

Value_measure = 
VAR CurrentDate = TODAY()
VAR FilteredFact = 
    FILTER(
        'Fact',
        'Fact'[Data from] > CurrentDate
    )
VAR LastRevValue = 
    CALCULATE(
        LASTNONBLANKVALUE('Rev'[Date], SUM('Rev'[Value])),
        TREATAS(VALUES('Fact'[INDEX]), 'Rev'[INDEX])
    )
VAR DaysBetween = 
    SUMX(
        FilteredFact,
        DATEDIFF('Fact'[Data from], 'Fact'[Data to], DAY)+1
    )
RETURN
    LastRevValue * DaysBetween

Output I have :

shafiz_p_0-1730696014590.png

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution and kudos!!

 

Best Regards,

Shahariar Hafiz

1.png2.png

You have not mentioned this calendar table in your post. However, how you are defining dates flaged as T. "Date From" is greater than current date, logic clear to me but How I would you go to another date table to find flag T. That means comparison criteria. 

Do you want to count days between "Date From" and "Date To" except those dates flaged as T in calendar table?

Please redefine you complete logic.

Should I start a separate post for my logic? Will it be possible to solve my problem in this thread?

Yes, I'm sorry I didn't include this in the logic earlier. So the logic is as before. Your dax works, but I would like to add logic to exclude days that have the "T" flag on the calendar

Do you want to count day between "Date from' and "Date to" excluding the Date Flagged as T. Meaning how you want to consider? What the logic behind this?

Yes, I'm sorry I didn't include this in the logic earlier. So the logic is as before. Your dax works, but I would like to add logic to exclude days that have the "T" flag on the calendar

v-yilong-msft
Community Support
Community Support

Hi @Kris48 ,

I tried to open your .pbix file, but I wasn't able to open it.

Just from your screenshot I don't fully know what data is in your table.

There are a lot of column names that do not appear in your DAX code.

Please provide the relevant example data if you can or use Dropbox for the .pbix file upload.

 

 

Best Regards

Yilong Zhou

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.