Forum Discussion
sql code in Dax
TomMartens thanks for this.
Now lets say I have a table with information regarding to the car park table A which gives the number of spaces in the car park area during a given timeframe.
Table B, is a calcuated table showing by date customers in the car park area, so for example on the 01/05/2019 1 customer was in car park zone A & left car park area, 3 customers were in car park zone B with 3 in left car park area.
I want to combine the two tables to say that when Date from table B is between 'from date' and 'to date' in table A and car park and car park area from B is equal to car park and car park area from table A then return the number of spaces in table B from table A. This should return table C
And finally to create a measure which will return results in table d
Table A:
| Car Park | Car Park Area | From Date | To Date | Spaces |
| Zone A | Left | 01/05/2019 | 20/05/2019 | 10 |
| Zone A | Right | 01/05/2019 | 20/05/2019 | 20 |
| Zone B | Left | 01/05/2019 | 20/05/2019 | 30 |
| Zone B | Right | 01/05/2019 | 20/05/2019 | 15 |
| Zone A | Left | 01/06/2019 | 20/06/2019 | 15 |
| Zone A | Right | 01/06/2019 | 20/06/2019 | 60 |
| Zone B | Left | 01/06/2019 | 20/06/2019 | 35 |
| Zone B | Right | 01/06/2019 | 20/06/2019 | 70 |
Table b:
| Date | CustomerID | CarPark | CarPark Area |
| 01/05/2019 | 123 | Left | ZoneA |
| 01/05/2019 | 127 | Left | ZoneB |
| 01/05/2019 | 130 | Left | ZoneB |
| 01/05/2019 | 133 | Left | ZoneB |
Table c
| Date | CustomerID | CarPark | CarPark Area | Spaces |
| 01/05/2019 | 123 | Left | ZoneA | 10 |
| 01/05/2019 | 127 | Left | ZoneB | 30 |
| 01/05/2019 | 130 | Left | ZoneB | 30 |
| 01/05/2019 | 133 | Left | ZoneB | 30 |
then measures to show
01/05/2019 occupancy for carpark left zone b was (count(customerid)/30)= 3/30
Hey ninakarsa ,
to avoid any confusion about the date format, upload a pbix that contains sample but still represents your data model to onedrive or dropbox and share the link, if you use xlsx file(s) to create the sample data, upload these file(s) as well.
Why is table B calculated, and what is the source for this calculation?
Regards,
Tom