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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
KXuan
Regular Visitor

How to get distinct value over overlaping period while filtering on one year

Hello everyone,

I need you help, I've been trying to solve this problem for several days and still don't know what to do.

I have a contract with 2 rows in my fact table, the first line is when the contract beginns and the second line is the extension. Both have the same price of 17,99Euro. According to bussiness definition , if I filter on 2019, I need to get the price 17,99 once in total, because the price should be considered only once in one year (2019).

 

Unbenannt.JPG

And if I do not filter, then I should get the sume of those, since I'm querying the entire period. In this case, my measure works.  Has anyone faced this problem, or has idea how to solve this with dax ?

 

Unbenannt1.JPG

 

Here is my measure :

 

var minDate = [minSelectedDate (Date)]
var maxDate = [maxSelectedDate (Date)]
return
CALCULATE(sum( '(F) Contract'[Price])
                ,   '(F) Contract'[Begin]<= maxDate &&  '(F) Contract'[End] >=minDate
 
        )

 

 

Thanks,

Xuan

1 ACCEPTED SOLUTION
KXuan
Regular Visitor

I solved that problem by using summarize:)

View solution in original post

3 REPLIES 3
KXuan
Regular Visitor

I solved that problem by using summarize:)

v-mengmli-msft
Community Support
Community Support

Hi @KXuan ,

 

Do you want to filter the table when year is selected in slicer? For example, when user selects 2019, the first row will be filtered.

vmengmlimsft_0-1722481879345.png

 

Please modify your original Dax expression as following.

 

Measure  =
  var minyear= MIN('(F) Contract' [Beigin])
  var maxyear= MAX('(F) Contract' [End])
  RETURN
  IF(SELECTEDVALUE(Table2[Year]) <> BLANK() , IF(SELECTEDVALUE(Table2[Year]) > YEAR(minyear) && SELECTEDVALUE(Table2[Year]) <= YEAR(maxyear) , 1 , 0) , 3)

 

 

Then set Filter as following.

vmengmlimsft_1-1722481879351.png

 

Here is my test for your reference.

vmengmlimsft_4-1722482246614.png

 

 

Best regards,

Mengmeng Li

 

 

Hello Mengmeng ,

Unfortunately, it's not what I want :(. Actually ,I just want to have the correct total without filtering in the table as in you example. 

The idea of this measure is to get the price of contract which is valid in selected period ( so I think _maxyear und _minyear should be based on seperate date dimension instead ).  In this example, it's 17,99 for 2019 or 2020 and 35,98 for the entire period.

 

Hope, that I explaned it well 😞

 

 

Best,

Xuan

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.