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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
sivarajan21
Post Prodigy
Post Prodigy

Dax values returned in visual does not match with data

Hi Team,

 

We have usage column in our TargetTimeseries table as below. Now we have to create dax for Target consumption per day.

sivarajan21_0-1728046849401.png

 

We need to divide this usage column with above Number of days between Startdate & Enddate to get the daily consumption. so we created a dax measure as below:

 

Target consumption per day = 
VAR minDate = MIN( 'Calendar'[Date] )
VAR maxDate = MAX( 'Calendar'[Date] )
RETURN
    SUMX(
        TargetTimeSeries,
        DIVIDE(TargetTimeSeries[Usage],IF(
            TargetTimeSeries[EndDate] < minDate || TargetTimeSeries[StartDate] > maxDate,
            BLANK( ),
            INT( MIN( TargetTimeSeries[EndDate], maxDate ) - MAX( TargetTimeSeries[StartDate], minDate ) ) + 1
        )
    )
    )

 

 

Below is the output in visual:

sivarajan21_1-1728046350626.png

 

we did a data analysis with data in model to find whether values returned by measure in visual is accurate.

So we took NetworkRail-3429. For below filter(1st April 2023) on StartDate,EndDate will show 31s March 2024 for this start date,  usage column should add up to give  12519260.(Took it to excel) 

sivarajan21_2-1728046412110.png

 

Then according to above 'Target consumption per day' dax, dividing this 12519260 with Number of days between startdate & EndDate which is 365. The result should be 12519260/365 = 34299.

This 34299 should be populated for all months of table visual as below:

sivarajan21_3-1728046462103.png

But we are not sure where & how below values are calculated in below table visual:

sivarajan21_0-1728045891706.png

We suspect because there is no relationship between Enddate(TargetTimeSeries) and Date(Calendar) & only startdate-Date relation is active this issue occurs. But not sure how to resolve this issue.

 
The current relationship between these two tables is as below:

sivarajan21_4-1728046520907.png

 

Could please advise me on this?

Please let me know if you need further info!

 

PFA file here TimeSeries Test.pbix

Also, FYR PFA file of filtered Network Rail data NetworkRail3429 data.xlsx

 

Many thanks in advance!

@marcorusso @Greg_Deckler @amitchandak @jgeddes @Anonymous @Anonymous @Ahmedx @v-cyu 

1 ACCEPTED SOLUTION
marcorusso
Most Valuable Professional
Most Valuable Professional

Something like that?

 

Target consumption = 
VAR minDate = MIN ( 'Calendar'[Date] )
VAR maxDate = MAX ( 'Calendar'[Date] )
RETURN  CALCULATE (
    SUMX ( 
        TargetTimeSeries,
        VAR _Days = TargetTimeSeries[EndDate] - TargetTimeSeries[StartDate] +1
        VAR _DailyConsumption = TargetTimeSeries[Usage] / _Days
        VAR _StartDate = MAX ( TargetTimeSeries[StartDate], minDate )
        VAR _EndDate = MIN ( TargetTimeSeries[EndDate], maxDate )
        VAR _DaysDisplayed = _EndDate - _StartDate + 1
        VAR Result = _DailyConsumption * _DaysDisplayed
        RETURN Result
    ),
    REMOVEFILTERS ( 'Calendar' ),
    KEEPFILTERS ( TargetTimeSeries[EndDate] >= minDate ),
    KEEPFILTERS ( TargetTimeSeries[StartDate] <= maxDate )
)

 

View solution in original post

8 REPLIES 8
marcorusso
Most Valuable Professional
Most Valuable Professional

I'd say the report is probably correct. When you filter the data view, the filter is not applied to the report.

If you want to create a filter on the start date at the report level and see the effects of that filter in the cost applied to the following months, you should duplicate the date column and apply different filters. However, I guess you only wanted to test your calculation, so it would be easier to compute the target consumption per day in each column, either in Power Query or DAX. A calculated column in DAX can be:

DailyConsumption = 
VAR _Days = TargetTimeSeries[EndDate] - TargetTimeSeries[StartDate]
VAR Result = TargetTimeSeries[Usage] / _Days
RETURN Result

Then, you can apply the events in progress pattern and write the following calculation:

Target consumption per day = 
VAR minDate = MIN ( 'Calendar'[Date] )
VAR maxDate = MAX ( 'Calendar'[Date] )
RETURN CALCULATE (
    SUM ( TargetTimeSeries[DailyConsumption] ),
    REMOVEFILTERS ( 'Calendar' ),
    KEEPFILTERS ( TargetTimeSeries[EndDate] >= minDate ),
    KEEPFILTERS ( TargetTimeSeries[StartDate] <= maxDate )
)

 

You can also avoid the calculated column by using a single measure:

Target consumption per day = 
VAR minDate = MIN ( 'Calendar'[Date] )
VAR maxDate = MAX ( 'Calendar'[Date] )
RETURN  CALCULATE (
    SUMX ( 
        TargetTimeSeries,
        VAR _Days = TargetTimeSeries[EndDate] - TargetTimeSeries[StartDate]
        VAR Result = TargetTimeSeries[Usage] / _Days
        RETURN Result
    ),
    REMOVEFILTERS ( 'Calendar' ),
    KEEPFILTERS ( TargetTimeSeries[EndDate] >= minDate ),
    KEEPFILTERS ( TargetTimeSeries[StartDate] <= maxDate )
)

 

Pay attention to the data because when you consider "April 2023" you have rows with a start date other than April 1, 2023.
I hope it helps.

 

Hi  @marcorusso

 

Thanks for your patience Sir!

We have tested this and it works exceptionally well! Also, I was able to understand events in progress clearly well this time.

 

In another case, I am confused on getting Target consumption per month from the same measure. What I mean is, from below measure we are able to calculate 'target consumption per day' which is great!.

with this daily value, we now need to use this daily value to multiply by the number of days in the month of the visual to apportion this consumption correctly.

 

Dax

Target consumption per day = 
VAR minDate = MIN ( 'Calendar'[Date] )
VAR maxDate = MAX ( 'Calendar'[Date] )
RETURN  CALCULATE (
    SUMX ( 
        TargetTimeSeries,
        VAR _Days = TargetTimeSeries[EndDate] - TargetTimeSeries[StartDate]
        VAR Result = TargetTimeSeries[Usage] / _Days
        RETURN Result
    ),
    REMOVEFILTERS ( 'Calendar' ),
    KEEPFILTERS ( TargetTimeSeries[EndDate] >= minDate ),
    KEEPFILTERS ( TargetTimeSeries[StartDate] <= maxDate )
)

for example,

ie. if the target table started on 17/04/2023 and ended on 31/03/2024 then the daily value would be multiplied by 14. because there are 14 days in April that this relates to. green color indicates what we already achieved.

Yellow color(Target consumption per month) is what we need to find. FYR, PFA below excel file that contains few formulas for better understanding NetworkRail3429 data.xlsx

sivarajan21_0-1728309213043.png

Target consumption per month should sum up this 14 days values and display for its respective month. 

sivarajan21_1-1728310587615.png

 

PFA file TimeSeries Test.pbix

Please advise!

 

Thanks in advance!

@marcorusso @Greg_Deckler @Ahmedx @amitchandak @Anonymous @Anonymous 

marcorusso
Most Valuable Professional
Most Valuable Professional

Something like that?

 

Target consumption = 
VAR minDate = MIN ( 'Calendar'[Date] )
VAR maxDate = MAX ( 'Calendar'[Date] )
RETURN  CALCULATE (
    SUMX ( 
        TargetTimeSeries,
        VAR _Days = TargetTimeSeries[EndDate] - TargetTimeSeries[StartDate] +1
        VAR _DailyConsumption = TargetTimeSeries[Usage] / _Days
        VAR _StartDate = MAX ( TargetTimeSeries[StartDate], minDate )
        VAR _EndDate = MIN ( TargetTimeSeries[EndDate], maxDate )
        VAR _DaysDisplayed = _EndDate - _StartDate + 1
        VAR Result = _DailyConsumption * _DaysDisplayed
        RETURN Result
    ),
    REMOVEFILTERS ( 'Calendar' ),
    KEEPFILTERS ( TargetTimeSeries[EndDate] >= minDate ),
    KEEPFILTERS ( TargetTimeSeries[StartDate] <= maxDate )
)

 

Hi @marcorusso ,

 

Your solution is a gem!

This is bringing a correct values and we have tested it for multiple use cases! It works!

sivarajan21_0-1728551986853.png

I have become a big fan of keep filters Keepfilters  and remove filters.

Is there any sqlbi article on remove filters?

 

I will close this query & accept this as solution!

 

Many thanks!

marcorusso
Most Valuable Professional
Most Valuable Professional

Look at related articles: REMOVEFILTERS – DAX Guide

Hi @marcorusso ,

 

Apologise for the delay in response!

Thanks for your quick & elegant response along with amazing dax!😍

Still we are testing it for multiple scenarios! I will work on it and get back with results!

 

Thanks for your patience!

Greg_Deckler
Community Champion
Community Champion

@sivarajan21 Maybe try this:

Target consumption per day = 
VAR minDate = MIN( 'Calendar'[Date] )
VAR maxDate = MAX( 'Calendar'[Date] )
RETURN
    SUMX(
        ALL( TargetTimeSeries ),
        DIVIDE(TargetTimeSeries[Usage],IF(
            TargetTimeSeries[EndDate] < minDate || TargetTimeSeries[StartDate] > maxDate,
            BLANK( ),
            INT( MIN( TargetTimeSeries[EndDate], maxDate ) - MAX( TargetTimeSeries[StartDate], minDate ) ) + 1
        )
    )
    )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

 

Thanks for your quick response on this!

Tried your measure, but this doesn't give the desired result:

sivarajan21_0-1728103452214.png

My dax works were StartDate & EndDate have same months(may month in this below example):

sivarajan21_1-1728103682345.png

But dax finds it difficult when there are multiple months(April 2023 to March 2024) between date range as below:

sivarajan21_2-1728103811103.png

 

Please advise how to deal this!

 

Thanks in advance!

@Greg_Deckler @marcorusso @Ahmedx @amitchandak @Anonymous @Anonymous 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors