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
justinleow
Frequent Visitor

Accumulative calculation over 2 databases

Dear All,


Thank you so much in advance to help me with my this problem as I cannot figure how to make it work. I am currently making a PowerBI dashbaord on sales performance report, which gets data from 2 databases. (1) is the product databse with inidival sales targets, and also a transaction database where all individual sales is made.

See a dummy database below,
Database.png 

This is the a output i an able to achieved currently (in tabular form). What I need is to have a report that show the percentage of the sales compard to the sales target of individual products in a monthly trend. The way I acheive this is definitely not the most efficient way as I am very new to DAX. 

 

I created a calculated table by summerize the "Sales database" to unqiue product ID, which then I lookupvalue the sales target of individual prodcut ID from the product database into the new calculated table. Then have a calculated measure to calculate the sales performance as shown in the achieved tabel below. 
Table.png

 

However, my final expected output is not just deplaying the performance of individual months but a accumulative one over the 6 months. I am not able to do that as my projected sales target do not have a time definitation.

 

EXPECTED OUTPUT
Table2.png

Thank you so much for giving me some ideas or guidance to how to achieve it. Deeply thank you for your teachings.

 

Best Regards,

Justin Leow

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @justinleow,

 

You can't direct achieve rolling total on actual sale table, because some products missed records of specific range.
I'd like to suggest you create new table to add missed records, then write a formula to calculate running total.

 

Expand table:

Expand = 
VAR temp =
    SELECTCOLUMNS ( Sales, "Product ID", [Product ID], "Sale month", [Sale month] )
VAR fulltable =
    SELECTCOLUMNS (
        CROSSJOIN (
            VALUES ( Sales[Product ID] ),
            VALUES ( Sales[Sale month] )
        ),
        "Product ID", [Product ID],
        "Sale month", [Sale month]
    )
RETURN
FILTER(
    UNION (
        Sales,
        SELECTCOLUMNS (
            EXCEPT ( fulltable, temp ),
            "TransactID", 0,
            "Product ID", [Product ID],
            "Sale month", [Sale month],
            "Sales Amount", 0
        )
    ), [Product ID] <> "Cancelled" )

Measures:

Actual total = 
CALCULATE (
    SUM ( Expand[Sales Amount] ),
    FILTER (
        ALLSELECTED ( Expand ),
        [Product ID] IN VALUES ( Expand[Product ID] )
            && [Sale month] <= MAX ( [Sale month] )
    )
)

Total Product = 
CALCULATE (
    SUM ( 'Product'[Monthly Projectedsales[*divide by 6]]),
    FILTER (
        ALLSELECTED ( 'Product' ),
        [ProductID] IN VALUES ( 'Product'[ProductID] )
            && [Sale month] <= MAX ( [Sale month] )
    )
)

Percent = 
VAR Actual =
    CALCULATE (
        SUM ( Expand[Sales Amount] ),
        FILTER (
            ALLSELECTED ( Expand ),
            [Product ID] IN VALUES ( 'Product'[ProductID] )
                && [Sale month] <= MAX ( 'Product'[Sale month] )
        )
    )
RETURN
    Actual / [Total Product]

4.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @justinleow,

 

You can't direct achieve rolling total on actual sale table, because some products missed records of specific range.
I'd like to suggest you create new table to add missed records, then write a formula to calculate running total.

 

Expand table:

Expand = 
VAR temp =
    SELECTCOLUMNS ( Sales, "Product ID", [Product ID], "Sale month", [Sale month] )
VAR fulltable =
    SELECTCOLUMNS (
        CROSSJOIN (
            VALUES ( Sales[Product ID] ),
            VALUES ( Sales[Sale month] )
        ),
        "Product ID", [Product ID],
        "Sale month", [Sale month]
    )
RETURN
FILTER(
    UNION (
        Sales,
        SELECTCOLUMNS (
            EXCEPT ( fulltable, temp ),
            "TransactID", 0,
            "Product ID", [Product ID],
            "Sale month", [Sale month],
            "Sales Amount", 0
        )
    ), [Product ID] <> "Cancelled" )

Measures:

Actual total = 
CALCULATE (
    SUM ( Expand[Sales Amount] ),
    FILTER (
        ALLSELECTED ( Expand ),
        [Product ID] IN VALUES ( Expand[Product ID] )
            && [Sale month] <= MAX ( [Sale month] )
    )
)

Total Product = 
CALCULATE (
    SUM ( 'Product'[Monthly Projectedsales[*divide by 6]]),
    FILTER (
        ALLSELECTED ( 'Product' ),
        [ProductID] IN VALUES ( 'Product'[ProductID] )
            && [Sale month] <= MAX ( [Sale month] )
    )
)

Percent = 
VAR Actual =
    CALCULATE (
        SUM ( Expand[Sales Amount] ),
        FILTER (
            ALLSELECTED ( Expand ),
            [Product ID] IN VALUES ( 'Product'[ProductID] )
                && [Sale month] <= MAX ( 'Product'[Sale month] )
        )
    )
RETURN
    Actual / [Total Product]

4.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.