cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Zagzebski Member
Member

Use Calendar Current Month to filter on non-related table

If I have two simple tables:

 

Calendar:

Date              Work Day

20180101              0

20180102              0

20180103              1

20180104              0

20180105              1

20180106              0

20180107              1

 

Revenue:

DateRevenue      Rev

20180101           100

20180103           200

20180104           300

20180104           400

20180107           500

20180107           600

 

These two tables are not linked in the model. I need to create a DAX meaure.  Work Day would be a slicer - when the user selects "1" all Revenue where "DateRevenue" equals the "Date" field would be summed. In this example the total would be 1300 which is the total of dates 20180107 and 20180103 (the values that have a "1" in the calendar table.)

 

Thanks,

Z

 

1 ACCEPTED SOLUTION

Accepted Solutions
dearwatson Member
Member

Re: Use Calendar Current Month to filter on non-related table

Yep I know the pain,

 

You can create any number of relationships between a master calendar and multiple date columns in a fact but only 1 can be "enabled" to prevent a circular reference. You may have seen this if you try and join the calendar twice to the same fact - one solid line and one dotted line relationship - you can enable/disable any relationship by going to its properties and select "make this relationship active" tickbox

 

To get around this you can hard code a measure to force the relationship:

 

heres a toob which probably explains it better than me:

 

sqlbi have a puzzle around this common scenario:

https://www.sqlbi.com/daxpuzzle/userelationship/

 

"The commonality between science and art is in trying to see profoundly - to develop strategies of seeing and showing." - Edward Tufte
8 REPLIES 8
dearwatson Member
Member

Re: Use Calendar Current Month to filter on non-related table

Probably the simplest solution is to created a disabled relationship between the Calendar[Date] and Revenue [DateRevenue] 

 

Then build a measure like so:

Revenue = CALCULATE([Total Revenue],USERELATIONSHIP('Date'[Date],Revenue[DateRevenue]))

Capture.PNG

 

Capture2.PNG

 

 

 

 

 

"The commonality between science and art is in trying to see profoundly - to develop strategies of seeing and showing." - Edward Tufte
Zagzebski Member
Member

Re: Use Calendar Current Month to filter on non-related table

Thanks for the response.

 

The problem is we have a ton of date fields in our model so it isn't possible to create a relationship to the calendar for each date field in each dimensions and fact table.

 

Can you explain "disabled relationship"? Might be what I need...

 

Z

dearwatson Member
Member

Re: Use Calendar Current Month to filter on non-related table

Yep I know the pain,

 

You can create any number of relationships between a master calendar and multiple date columns in a fact but only 1 can be "enabled" to prevent a circular reference. You may have seen this if you try and join the calendar twice to the same fact - one solid line and one dotted line relationship - you can enable/disable any relationship by going to its properties and select "make this relationship active" tickbox

 

To get around this you can hard code a measure to force the relationship:

 

heres a toob which probably explains it better than me:

 

sqlbi have a puzzle around this common scenario:

https://www.sqlbi.com/daxpuzzle/userelationship/

 

"The commonality between science and art is in trying to see profoundly - to develop strategies of seeing and showing." - Edward Tufte
MarkLaf Member
Member

Re: Use Calendar Current Month to filter on non-related table

Another option is to use SUMX. Add a table or matrix with Calendar[Date] as rows and then the below measures. Not sure if you actually don't want to count Rev at all unless it's on a work day or if you just want to be able to filter by workday, so I provided two:

 

WorkFilter = SUMX('Calendar',0+CALCULATE(SUM(Revenue[Rev]),FILTER(Revenue,Revenue[dateRevenue]='Calendar'[Date])))
WorkOnly = SUMX('Calendar',0+CALCULATE(SUM(Revenue[Rev]),FILTER(Revenue,Revenue[dateRevenue]='Calendar'[Date] && 'Calendar'[Work Day]=1)))

notfiltered.PNGfiltered.PNG

 

If you would prefer there to be blanks instead of 0's for days with no revenue, just remove the "0+" in front of the CALCULATE.

mattbrice Senior Member
Senior Member

Re: Use Calendar Current Month to filter on non-related table

Something like this may work for you:

 

Measure =
CALCULATE (
    SUM ( Revenue[Rev] ),
    INTERSECT ( VALUES ( Revenue[DateRevenue] ), VALUES ( Calendar[Date] ) )
)
Zagzebski Member
Member

Re: Use Calendar Current Month to filter on non-related table

Very helpful! Thanks.

Zagzebski Member
Member

Re: Use Calendar Current Month to filter on non-related table

Thanks - new to Power Bi - helps alot.

Zagzebski Member
Member

Re: Use Calendar Current Month to filter on non-related table

Thanks

Helpful resources

Announcements
Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

PBI Community Highlights

PBI Community Highlights

Check out what's new in the Power BI Community!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Kudoed Authors
Users Online
Currently online: 266 members 3,278 guests
Please welcome our newest community members: