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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Pio_Mat
New Member

Calculated table from two tables: aggregated plus detailed

Hi,

please anyone help me to solve following issue.

 

I have two tables (see also screens):

  • One, SALES_PREV_MOTHS, with aggregated monthly, historical sales data per customer.
    This table is quite large and I do not want it to be refreshed.
  • Second table, SALES_CURRENT_MNTH, with daily sales figures per customer.
    This table is refreshed on daily basis.

Expected outcom is to have a third table, SALES_TOTAL, with aggregated monthly sales per customer, where current month's figures will adjust when SALES_CURRENT_MNTH table is refreshed.

 

Thanks for an advice! 🙂

 

Pio_Mat_0-1695565650306.png

 

1 ACCEPTED SOLUTION
gmsamborn
Super User
Super User

Hi @Pio_Mat 

Would something like this help?

_SummaryTable = 
VAR _Table =
    SUMMARIZE(
        'SALES_CURR_MTH',
        'SALES_CURR_MTH'[CustomerID],
        "Year-month",
            VAR _Dt = MIN( 'SALES_CURR_MTH'[Date] )
            VAR _Yr = YEAR( _Dt )
            VAR _Mon = MONTH( _Dt )
            RETURN
                DATE( _Yr, _Mon, 1),
        "Sales",
            SUM( 'SALES_CURR_MTH'[Sales] )
    )
RETURN
    UNION(
        'SALES_PREV_MTHS',
        SELECTCOLUMNS(
            _Table,
            "Year-month",
                [Year-month],
            "CustomerID",
                [CustomerID],
            "Sales",
                [Sales]
        )
    )

View solution in original post

4 REPLIES 4
gmsamborn
Super User
Super User

Hi @Pio_Mat 

Would something like this help?

_SummaryTable = 
VAR _Table =
    SUMMARIZE(
        'SALES_CURR_MTH',
        'SALES_CURR_MTH'[CustomerID],
        "Year-month",
            VAR _Dt = MIN( 'SALES_CURR_MTH'[Date] )
            VAR _Yr = YEAR( _Dt )
            VAR _Mon = MONTH( _Dt )
            RETURN
                DATE( _Yr, _Mon, 1),
        "Sales",
            SUM( 'SALES_CURR_MTH'[Sales] )
    )
RETURN
    UNION(
        'SALES_PREV_MTHS',
        SELECTCOLUMNS(
            _Table,
            "Year-month",
                [Year-month],
            "CustomerID",
                [CustomerID],
            "Sales",
                [Sales]
        )
    )

Thank you, @gmsamborn ,

after some small adjustments to my 'real' environment I got exactly what I was looking for.

Thank you so much!

🙂

some_bih
Super User
Super User

Hi @Pio_Mat in two tables, according to picture, there are different grain of granularity of data: mix monthly and daily level. My personal experience: the best is to have it on single level like on daily as it is easier to aggregate it on monthly / yearly level...

When you analyse your possibilities and next steps please check link how to do as possible example in Power Query on link below. Depending on your analysis maybe some other type of query would be needed in Power Query, but most probably Power Query is your best option.

https://learn.microsoft.com/en-us/power-query/append-queries 

Did I answer correctly? Kudos appreciate / accept solution.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Thank you, @some_bih !

My idea was more like to find a way to calculate cumulated current month's sales per customer from a table SALES_CURR_MTH and then, having data with the same granularity as in SALES_PREV_MTHS, union both?

My intuition says it should be doable but I am to new in DAX to find a way how to do that 🙂

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.