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
snayff
Regular Visitor

Returning Wrong SUM Result From Another Table

Objective

I'm trying to return 1 of 2 values based on whether 1 of those values exists. e.g. give me A if A exists, else B. These values are held in separate tables. More specifically, I have forecast values by provider, source and date and have actuals as a list of transactions, meaning multiple rows per provider, per month from each source. Where we have actuals I want to use those, else use the forecast. 

 

Problem

The forecast returns correctly, but the returned "actual" value is wrong, and in fact so wrong that I can't tie it back to any combination of numbers. 

 

Details

Here are the actuals and forecast by month for a specific source and provider. I'd expect `Spend_ActualOrForecast` to be 204,405.54 in June (same as actuals, because we have actuals) and 199,999 in July (same as forecast, because no actuals).

snayff_0-1691063341569.png

 

The calculated column in question

 

Spend_ActualOrForecast = 
    // use actual if we have it, else us forecast
    
    VAR resource_provider = 
        factForecast[Resource Provider]

    VAR source = 
        factForecast[Source.Name]

    VAR journal_type = 
        IF(
            resource_provider = "Us",
            "G",
            "P"
        )

    VAR start_date = 
        DATE(
            YEAR(factForecast[Forecast Anchor Date]),
            MONTH(factForecast[Forecast Anchor Date]),
            01
        )
    
    VAR end_date = 
        EOMONTH(
            DATE(
                YEAR(factForecast[Forecast Anchor Date]),
                MONTH(factForecast[Forecast Anchor Date]),
                01
            ),
            0
        )

    VAR actual = 
        CALCULATE(
            SUM(factTransactions[Account]) * -1,
            factTransactions[Normalised Expense Group] = resource_provider,
            factTransactions[Source.Name] = source,
            factTransactions[Journal Type] = journal_type,
            factTransactions[Reporting Date] >= start_date,
            factTransactions[Reporting Date] <= end_date
        )

    RETURN
        IF(
            actual = 0,
            factForecast[Forecast Value],
            actual
        )            

 

 

Sample Data

factForecast

Source.NameResource ProviderForecast ValueForecast Anchor DateSpend_ActualOrForecast
project1ABC£199,999July 23 
project1ABC£0December 23 
project1ABC£0November 23 
project1ABC£0October 23 
project1ABC£0September 23 
project1ABC£0August 23 
project1ABC£0June 23 
project1ABC£0May 23 
project1ABC£0April 23 
project1ABC£0March 23 
project1ABC£0February 23 
project1ABC£0January 23 
project1Us£0December 23 
project1Us£0November 23 
project1Us£0October 23 
project1Us£0September 23 
project1Us£0August 23 
project1Us£0July 23 
project1Us£0June 23 
project1Us£0May 23 
project1Us£0April 23 
project1Us£0March 23 
project1Us£0February 23 
project1Us£0January 23 

 

factTransactions

Source.NameAmountJournal TypeReporting DateNormalised Expense Group
project1-£204,406PJun 23ABC
project1£284GFeb 23Us
project1-£284GFeb 23Us
project1-£284GFeb 23Us
project1-£652PMar 23ABC

 

Any help would be greatly appreciated!

1 REPLY 1
snayff
Regular Visitor

Any chance someone has any thoughts on this? 🤞

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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