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
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
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.