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
TranquilBoy
New Member

Calculating and returning the value for each date in the calendar

Hello everyone!

 

Hope you all are doing well!

 

I am stuck with quite an issue here. Hope you can give me a few hints how to go on.

So, I have a dataset from 1 fact table and 4 dimensions:

Structure.png

The fact table has the next structure:

Fact.png

 

The problem is I can't quite get my head around how to get the desired result.

I need to produce the output of the next spreadsheet formula:

=SUMIFS(N:N;L:L;">="&Q3;G:G;"AUD";$K:$K;"<="&MIN($Q$3:$Q$46);$J:$J;MIN($Q$3:$Q$46))/SUMIFS(M:M;L:L;">="&Q3;G:G;"AUD";K:K;"<="&MIN($Q$3:$Q$46);J:J;MIN($Q$3:$Q$46))

The logic behind calculation:

- aggregate all calculated amounts ("CalculatedAmount" column; difference between Value date and Valuation date columns multiplied by the Amount) where:

  • Trade date is less than or equal to minimal date in user selected set;
  • Value date is bigger or equal to the date from user selected set;
  • Valuation date is equal to the min date is user selected set

- divide the formula above to the Amount aggregation with the same filter

 

I created the next DAX measure:

 

 

_calculation = 
VAR _minDate = MIN(DimDates[Date])
VAR _filteredTable = FILTER(FactTable,AND(AND(FactTable[Trade Date]<=_minDate,FactTable[Valuation Date] = _minDate),FactTable[Value Date]>=FactTable[Creation Date]))
VAR _result = SUMX(_filteredTable,(DATEDIFF(FactTable[Valuation Date],FactTable[Value Date],DAY)))
return _result

 

 

Power BI returns the correct value, which is 41:

TranquilBoy_0-1643099593005.png

However, I need to get result similar to SUMIFS one. The dataset satisfies the requirements not only for 29/10:

TranquilBoy_1-1643099719380.png

I have a hinch, that this is the result of inner join between dates and fact tables, but I do not see the solution of this issue.

How can I do this? Any hints or help will be appreciated!

pbix and xlsx files can be downloaded here: https://drive.google.com/drive/folders/1Moh-Icg24sCvI7tGXvUCWajm87II-IVE?usp=sharing

 

Thank you and have a nice day!

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @TranquilBoy ,

 

Please check if this is what you want:

CalculatedAmount Column =
DATEDIFF ( FactTable[Valuation Date], FactTable[Value Date], DAY ) * FactTable[Amount]
Measure 1 = 
VAR CurrentUserDate_ =
    MIN ( DimDates[Date] )
VAR MinxUserDate_ =
    MINX ( ALLSELECTED ( DimDates[Date] ), DimDates[Date] )
VAR SUM_CalculatedAmount =
    CALCULATE (
        SUM ( FactTable[CalculatedAmount Column] ),
        FactTable[Value Date] >= CurrentUserDate_,
        FactTable[Trade Date] <= MinxUserDate_,
        FactTable[Valuation Date] = MinxUserDate_,
        ALLSELECTED ( DimDates[Date] )
    )
VAR SUM_Amount =
    CALCULATE (
        SUM ( FactTable[Amount] ),
        FactTable[Value Date] >= CurrentUserDate_,
        FactTable[Trade Date] <= MinxUserDate_,
        FactTable[Valuation Date] = MinxUserDate_,
        ALLSELECTED ( DimDates[Date] )
    )
RETURN
    DIVIDE ( SUM_CalculatedAmount, SUM_Amount )

Icey_0-1643340277162.png

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Icey
Community Support
Community Support

Hi @TranquilBoy ,

 

Please check if this is what you want:

CalculatedAmount Column =
DATEDIFF ( FactTable[Valuation Date], FactTable[Value Date], DAY ) * FactTable[Amount]
Measure 1 = 
VAR CurrentUserDate_ =
    MIN ( DimDates[Date] )
VAR MinxUserDate_ =
    MINX ( ALLSELECTED ( DimDates[Date] ), DimDates[Date] )
VAR SUM_CalculatedAmount =
    CALCULATE (
        SUM ( FactTable[CalculatedAmount Column] ),
        FactTable[Value Date] >= CurrentUserDate_,
        FactTable[Trade Date] <= MinxUserDate_,
        FactTable[Valuation Date] = MinxUserDate_,
        ALLSELECTED ( DimDates[Date] )
    )
VAR SUM_Amount =
    CALCULATE (
        SUM ( FactTable[Amount] ),
        FactTable[Value Date] >= CurrentUserDate_,
        FactTable[Trade Date] <= MinxUserDate_,
        FactTable[Valuation Date] = MinxUserDate_,
        ALLSELECTED ( DimDates[Date] )
    )
RETURN
    DIVIDE ( SUM_CalculatedAmount, SUM_Amount )

Icey_0-1643340277162.png

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello, Icey.

Works just fine! Thanks a lot. At last I can get the progress moving forward!

Wishing you a very great day!

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.