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
Analitika
Post Prodigy
Post Prodigy

Calculate sum of quantity filtered by last date in table in Power BI

Hi,

 

I would like to ask how to calculate sum of quantity filtered by last date. I used many expressions which didn't help me. Formulae is this:

Analitika_0-1674473920516.png

kiekis_p = CALCULATE(SUMX(op_detales,op_detales[qty_in]), FILTER(op_detales,op_detales[modul]="Pirkimai" && op_detales[Dokumento data]=[_m_date_A]))

Measure for this.

 

But problem is that I am getting wrong result, it gives me 32 instead of 1. So seems it sums all values and date filter not working.

5 REPLIES 5
LQuedas
Resolver II
Resolver II

Hey @Analitika 

if I understood well you want to get the sum of a quantity value filtered by the latest date for a specific model (Pirkimai)... if I'm correct please try the following example... I'm assuming you have a dim and a fact table, if not you can use the same approach with a single table as well... so I've created a DimDate with a date column and a Sales Fact table with 4 columns, theDate that is a foreign key to the DimDate table, a Prod Name colum that will be used to filter the calculation and the Quantity Value...

LQuedas_0-1674477702176.png

With this model you can use the following simple Measure to get the the Sum of the quantity filtered by the latest date of a specific product,

CurrentSum =
var _maxDate=CALCULATE(max(FactSales[The Date]), Sales[ProductName]="Prod A")
return CALCULATE(sum(FactSales[QuantityValue]),DimDate[TheDate]=_maxDate)
 
Hope this example gives you an idea to solve your problem.
 
Cheers, LQ

 

Thennarasu_R
Responsive Resident
Responsive Resident

Hi @Analitika 
Try this Measure,
Measure=Var __Maxdate=Max(DimDate(date))
Return

kiekis_p = CALCULATE(SUM(op_detales[qty_in]), op_detales,op_detales[modul]="Pirkimai" , op_detales[Dokumento data]=__Maxdate))

Thanks,
Thennarasu



Hi,

 

I tried but not working, with max_date I am getting result null. So something is wrong. I expected to get 1 output. 

Analitika_0-1674475153125.png

 

Hi @Analitika 

Try this,

kiekis_p = CALCULATE(SUM(op_detales[qty_in]),Filter( Values(op_detales[Dokumento data]),op_detales[Dokumento data]=__Maxdate),op_detales[modul]="Pirkimai"))

Thanks,
Thennarasu

Just needed add && but idea is ok.

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.