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
Marek_Wojciech
Frequent Visitor

Problem with correctly filtering a fact table based on another table

Hi, I'm taking my first steps in DAX and I have a simple model consisting of two tables. I created two measures (Generation and Generation1), the first returns the sum of generations, the second also returns the sum, but limited by the ComDat dates from the bottom and the DeComDate date from the top for each unit. The results of the latter seem correct at the unit level, but the summary in the sums line is incorrect and returns the total generation. The solution is probably trivial for specialists, but please note that the actual tblGeneration table in my real model has 10 million records. Please indicate the correct definition of the Generation1 measure. Thank you in advance for your help.

Regards Marek_Wojciech,

tblUnits

 

 

Unit	ComDate	DeComDate
A	01.01.1900	03.01.2023
B	02.01.2023	01.01.2100
C	01.01.1900	01.01.2100
D	02.01.2023	04.01.2023​

 

 

tblGeneration

 

 

Date	Unit	power
01.01.2023	A	15
02.01.2023	A	17
03.01.2023	A	13
04.01.2023	A	12
01.01.2023	B	34
02.01.2023	B	24
03.01.2023	B	18
04.01.2023	B	0
01.01.2023	C	24
02.01.2023	C	13
03.01.2023	C	13
04.01.2023	C	20
01.01.2023	D	24
02.01.2023	D	13
03.01.2023	D	13
04.01.2023	D	20

 

 

Marek_Wojciech_0-1701206860908.png

 

 

DEFINE
    MEASURE 'tblGeneration'[DateComMeasure] = MIN('tblUnits'[ComDate])
    MEASURE 'tblGeneration'[DateDeComMeasure] = MAX('tblUnits'[DeComDate])
    MEASURE 'tblGeneration'[Generation] = SUMX('tblGeneration','tblGeneration'[power])
    MEASURE 'tblGeneration'[Generation1] = 
	VAR DCM=[DateComMeasure]
	VAR DDCM=[DateDeComMeasure]
RETURN
CALCULATE([Generation],AND('tblGeneration'[Date]<DDCM,'tblGeneration'[Date]>DCM))

 

 

Marek_Wojciech_1-1701204536962.png

 

 

5 REPLIES 5
parry2k
Super User
Super User

@Marek_Wojciech well you have a solution that's what matters, how we get there, maybe not that important. 🙂 Cheers!!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Marek_Wojciech try this:

 

Gen 1 Measure = 

SUMX(
    FILTER ( 
       'tblGen',

       'tblGen'[Date] < RELATED ( tblUnits[DeComDate] ) &&
       'tblGen'[Date] > RELATED ( tblUnits[ComDate] )
    ),
    'tblGen'[power]
)

 

parry2k_0-1701286440591.png

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

At the same time, after careful analysis, I came to the same solution. Thank you for your time and suggestion, which allowed me to find a solution.

parry2k
Super User
Super User

@Marek_Wojciech try this:

 

Gen 1 Measure = 
VAR __ComDate = MIN('tblUnits'[ComDate])
VAR __DeComDate =  MIN('tblUnits'[DeComDate])
RETURN
SUMX(
    FILTER ( 
       'tblGeneration',
       'tblGeneration'[Date] <= __DecComDate &&
       'tblGeneration'[Date] >= __ComDate
    ),
    'tblGeneration'[power]
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thank you for your answer, although the generation for individual units is correct, the summary is still wrong. It should be 133, not 164. This is the sum of the generation for each unit in the range between the ComDate and DeComDate dates of each unit (without generation on these days - in the measure >,< and not >= ,<=).

Marek_Wojciech_1-1701283956776.png

 

 

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.