Forum Discussion
How to write similar DAX query as per Subquery in SQL Server
- 6 years ago
Repeating values like this are generally indicative of a relationship issue.
Here the Visits table can't filter the PersonCalendar due to the direction of the relationship.
Solutions : change the direction to 'bidirectional' between Visits and PersonCalendar . Will work but may cause relationship problems for other results
OR
rework the data model. This would depend upon what you are trying to report on
OR
use CROSSFILTER to filter the PersonCalendar for just this measure e.g.
FiltAvailDays = CALCULATE([AvailableDays], CROSSFILTER(PersonCalendar[PersonIdDateKey], Visits[PersonIdDateKey], Both))
Hi AvPowerBI ,
I have tried but not certain:
table =
VAR tab =
CALCULATETABLE (
VALUES ( ec[calendarkey] ),
VALUES ( ec[availableflag] ),
VALUES ( c[customername] ),
FILTER (
CROSSJOIN ( ec, b ),
ec[db] = v[db]
&& ec[personid] = v[personid]
&& ec[personday] = FORMAT ( v[arrivedttm], "General Date" )
),
FILTER ( CROSSJOIN ( v, c ), v[db] = c[db] && v[callno] = c[callno] ),
OR ( YEAR ( v[arrivedttm] ) = 2019, YEAR ( v[arrivedttm] ) = 2020 )
&& ec[db] = 'UK'
)
RETURN
SUMMARIZE (
tab,
'c'[customername],
"AvailableDays", SUM ( 'ec'[availableflag] )
)
Refer the following articles:
- from-sql-to-dax-projection
- from-sql-to-dax-joining-tables/
- from-sql-to-dax-in-and-exists/
- from-sql-to-dax-grouping-data/
- from-sql-to-dax-filtering-data/
Best Regards,
Yingjie Li
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Hi V-yingl,
Thanks for your help so far, I've tried the way you have mentioned but was having issues implenting it and didn't realise it would be that complex the DAx query to get the result I wanted.
I have therefore provided an example and added the spreadsheet and pbix file on One Drive, you will see the results of what I want from the oneshare link below
https://1drv.ms/u/s!Aknl2UdxdHn0cTzGDcZPqkEDXcI?e=KXvDVU
Wish to have the below Results, when the Dimension is CustomerName but it keeps repeating the same value of 6
Thanks
- AvPowerBI6 years agoPost Patron
Wish to have the below Results, when the Dimension is CustomerName but it keeps repeating the same value of 6
- HotChilli6 years agoCommunity Champion
Repeating values like this are generally indicative of a relationship issue.
Here the Visits table can't filter the PersonCalendar due to the direction of the relationship.
Solutions : change the direction to 'bidirectional' between Visits and PersonCalendar . Will work but may cause relationship problems for other results
OR
rework the data model. This would depend upon what you are trying to report on
OR
use CROSSFILTER to filter the PersonCalendar for just this measure e.g.
FiltAvailDays = CALCULATE([AvailableDays], CROSSFILTER(PersonCalendar[PersonIdDateKey], Visits[PersonIdDateKey], Both))
- AvPowerBI6 years agoPost Patron
Thanks HotChilli,
I will have a look at these DAX functions you have mentoned, just wanted to check was you able to access the OneDrive folder I mentioned on the above post?
I am currently in a transition from QlikView to Power BI, where Qlikview had a function called Cyclic which you could cycle though different Dimensions and it would automatically work out the value for you, not having the same luck in Power BI I'm afraid.