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
Anonymous
Not applicable

Sum of latest values of all groups

Hello,

 

I have a data from database from where I pull out the latest values. After a long googling session I managed to create a measure, which pulls out the latest values 

 

Gross Sales (EUR) = 
VAR __myLastAmount = CALCULATE(LASTNONBLANK(Sales[Gross Sales LE (EUR)], ""), FILTER('Sales', Sales[EntryDate] = MAX(Sales[EntryDate])))
VAR __tmpTable = SUMMARIZE('Sales',[CustID], [Year], [ProductType], [Season],"__LastAmount",__myLastAmount)
RETURN SUMX(__tmpTable,[__LastAmount])

 

 

I group the data by CustID, Year, ProductType, Season and then find the latest GrossSales for the group based on EntryDate, which is datetime timestamp. Getting the latest values like this works, however I cannot find a way to get a total sum for these values.

Does anyone know how to do this?

 

Best regards,

Ales

1 ACCEPTED SOLUTION
rajulshah
Super User
Super User

Hello @Anonymous,

You can create a measure as below:

Total Gross Sales = 
VAR __tmpTable = SUMMARIZE('Sales',[CustID], [Year], [ProductType], [Season],"__LastAmount",__myLastAmount)
RETURN SUMX(__tmpTable,[Gross Sales (EUR) ])

Let me know if this didn't work. 

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

Try Something like this

 

sumx(  
        ADDCOLUMNS( 
            SUMMARIZE(
                Invoices;
                Invoices[Invoice ID]
            );
            "_Measure";
            calculate(
                sum(Invoices[Amount]);
                filter(
                    ALL(Invoices);
                    Invoices[Invoice ID]= earlier(invoices[Invoice ID])
                )
            )
        )
        ;[_Measure]
    )

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

 

 

Or try like

 

Calculate(
    sumx(  
        ADDCOLUMNS( 
            SUMMARIZE(
                data,
                data[NUM_DPL],
				"max_date",
				MAX( 'Date'[Date]),
                "Max_ID", max(data[NUM_DPL])
            ),
            "Over20K",
            calculate(
                Max(data[VLR_SLD_TOT_CAL]),
                filter(
                    all(data),
                    data[NUM_DPL]= [Max_ID] && data[DAT_REF]= ([max_date]) )
                )
            )
        ,[Over20K]
    )
)
rajulshah
Super User
Super User

Hello @Anonymous,

You can create a measure as below:

Total Gross Sales = 
VAR __tmpTable = SUMMARIZE('Sales',[CustID], [Year], [ProductType], [Season],"__LastAmount",__myLastAmount)
RETURN SUMX(__tmpTable,[Gross Sales (EUR) ])

Let me know if this didn't work. 

Anonymous
Not applicable

it works, thank you!!

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.

Top Solution Authors