Forum Discussion
Create a stacked bar chart visual by summing a column from two different table
- 3 years ago
Fix this part
Get rid of the Month Lookup table, and add a Date column to your Target table. Can be the first of the month, for example.
Hi lbendlin ,
Apologise for the delay in response!
Thanks for your superb idea and I had worked on this and tested a lot.
We are very close to the solution, and here is my observation:
Dax code written was:
Accrual kwh =
COALESCE ( [Profile], [Direct], [Target accrual] )
The dax measures inside COALESCE are as below:
Profile =
CALCULATE ( SUM ( Data[Units] ), FILTER ( Data, Data[Source] = "Profile" ) )
Target accrual =
CALCULATE (
SUM ( 'Missing Calendar date'[Target Unit] ),
USERELATIONSHIP ( 'Missing Calendar date'[Date], 'Calendar'[Date] )
)
Direct =
CALCULATE ( SUM ( Data[Units] ), FILTER ( Data, Data[Source] = "Direct" ) )
My sample dataset are as below:
Data table:
| Date | Points | Source | Units | Last Update | Cost | DS |
| 01 March 2023 | INSE-965 | Profile | 410.7420044 | 1 | ||
| 02 March 2023 | INSE-965 | Profile | 406.1069946 | 1 | ||
| 03 March 2023 | INSE-965 | Profile | 471.0010376 | 1 | ||
| 04 March 2023 | INSE-965 | Profile | 306.3860168 | 1 | ||
| 05 March 2023 | INSE-965 | Profile | 0 | 1 | ||
| 06 March 2023 | INSE-965 | Profile | 436.7469482 | 1 | ||
| 07 March 2023 | INSE-965 | Profile | 415.3769531 | 1 | ||
| 08 March 2023 | INSE-965 | Profile | 499.9590149 | 1 | ||
| 01 February 2023 | INSE-100 | Direct | 50 | 1 | ||
| 02 February 2023 | INSE-100 | Profile | 44 | 1 | ||
| 03 February 2023 | INSE-100 | Invoice | 20 | 1 | ||
| 04 February 2023 | INSE-100 | Profile | 10 | 1 |
Missing Calendar date_1
| DB Name - Points Id | Date | Target Unit | Target Cost |
| INSE-965 | 09 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 10 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 11 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 12 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 13 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 14 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 15 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 16 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 17 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 18 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 19 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 20 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 21 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 22 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 23 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 24 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 25 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 26 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 27 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 28 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 29 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 30 March 2023 | 0.894999995 | 5.196775402 |
| INSE-965 | 31 March 2023 | 0.894999995 | 5.196775402 |
| INSE-100 | 05 February 2023 | 0.955654638 | 6.825658 |
| INSE-100 | 06 February 2023 | 0.955654638 | 6.825658 |
| INSE-100 | 07 February 2023 | 0.955654638 | 6.825658 |
| INSE-100 | 08 February 2023 | 0.955654638 | 6.825658 |
Target Table
| DBName-Point_Id | TargetType | Value Type | Value | Source_Num | Source | Month |
| INSE-965 | 0 | Value_03 | 900.37 | 4 | Budget | March |
| INSE-965 | 1 | Value_03 | 5227.956 | 4 | Budget | March |
The above sample dataset can be found in below link:
COALESCE Function not working.pbix
When I used this measure 'Accrual kwh' in visual it includes only the first argument ' [Profile]' and doesn't include '[Direct]' & '[Target accrual]'. For example, INSE-965 has total of 2946.318(Accrual kwh) Units for Source Profile from 1st March 2023 to 8th March 2023 which shown as in below visual highlighed in red:
The same is shown in above tabular visual.
what we wanted to achieve is to fill(sum) the units for missing dates in Data table with the Missing calendar date table. for we have 1st March 2023 to 8th March 2023 in Data table and from 09 march 2023 to 31st March 2023 is found in Missing Calendar date table.
The expected output should be as below:
| Month | Invoice | Target | Accrual kwh | Target accrual | Direct | Profile |
| February | 20 | 107.82 | 3.82 | 50 | 54 | |
| March | 900.37 | 2966.9 | 20.58 | 2946.32 |
That is 'Accrual kwh' measure will contain sum of values in order of
February -- >54 (Profile) + 50 (Direct) + 3.82 (Target Accrual ) =107.82
March ---> 2946.32 (Profile) + BLANK (Direct) + 20.58 (Target Accrual ) = 2966.9
I am confused in using COALESCE function.
Could you please help me to solve & whether we can use this or some other dax?
Thanks in advance.
Ahmedx lbendlin Ashish_Mathur grantsamborn Greg_Deckler amitchandak onurbmiguel_ VijayP Idrissshatila
Fix this part
Get rid of the Month Lookup table, and add a Date column to your Target table. Can be the first of the month, for example.