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
yvesdeutschmann
New Member

SUM w/o duplicates for dynamic list of dates

Hi,

 

I'm trying to accomplish a seemingly easy aggregation but just can't wrap my head around how exactly. I have 3 tables:

  • Prices: PartID, Price, GroupID, Date
    • PartID can occur multiple times
  • DimDate: all Days for a certain interval
  • Mondays: Dates of all Mondays for a certain interval
    • The list of Mondays is generated dynamically and will grow over time

 

What I'm ultimately looking for is the sum of all prices before each Monday in the above list.

  • if a PartID is duplicated in the list, I only want the most recent entry to be considered for the sum
  • I want to be able to group the result be GroupID

The chart I want to build looks something like this, only with the Mondays on the x-axis.

yvesdeutschmann_0-1643397198350.png

 

Can someone point me in the right direction on how to do this? This is the PBIX Sample.

 

TIA Yves

1 ACCEPTED SOLUTION
yvesdeutschmann
New Member

I finally figured it out. In case anyone runs into the same problem, here's what I did:

 

I had to remove the connection between Prices[Date] and DimDate[Date]:

yvesdeutschmann_0-1643466917306.png

 

After that the measures, I had in place finally worked together:

  • SelectedDate = SELECTEDVALUE(DimDate[Date]) => represents the "selected" Monday
  • LatestPrice =

VAR _maxdate = [SelectedDate]

RETURN CALCULATE( SELECTEDVALUE(Prices[Price]),  Prices[Date] < _maxdate  )

  • TotalProductCost =
    VAR _table = SUMMARIZE(  Prices, Prices[PartID], "_value", [LatestPrice])
    RETURN SUMX(_table, [_value])

 

The updated PBIX can be found HERE and now looks like this:

yvesdeutschmann_1-1643467402731.png

 

Regards,

Yves

View solution in original post

1 REPLY 1
yvesdeutschmann
New Member

I finally figured it out. In case anyone runs into the same problem, here's what I did:

 

I had to remove the connection between Prices[Date] and DimDate[Date]:

yvesdeutschmann_0-1643466917306.png

 

After that the measures, I had in place finally worked together:

  • SelectedDate = SELECTEDVALUE(DimDate[Date]) => represents the "selected" Monday
  • LatestPrice =

VAR _maxdate = [SelectedDate]

RETURN CALCULATE( SELECTEDVALUE(Prices[Price]),  Prices[Date] < _maxdate  )

  • TotalProductCost =
    VAR _table = SUMMARIZE(  Prices, Prices[PartID], "_value", [LatestPrice])
    RETURN SUMX(_table, [_value])

 

The updated PBIX can be found HERE and now looks like this:

yvesdeutschmann_1-1643467402731.png

 

Regards,

Yves

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.