Forum Discussion
Create a stacked bar chart visual by summing a column from two different table
Hi,
I have tried so many ways to create this measure, but could not figure out correctly.
Below is my sample dataset:
Data Table:
| Date | Acrual | Source |
| 01/01/2022 | 1 | Profile |
| 02/01/2022 | 2 | Profile |
| 03/01/2022 | 1 | Direct |
| 07/01/2022 | 1 | Direct |
Missing Date Table:
| Date | Target |
| 04/01/2022 | 1 |
| 05/01/2022 | 1 |
| 06/01/2022 | 2 |
I need a measure to calculate sum of Acrual in Data table for their corresponding Date and Source. If the the Date is missing in Data table for example Missing Date table contains the Date(04/01/2022,05/01/2022 and 06/01/2022) that is not present in
Data table. For those missing dates, we need to sum those Target in Missing Date Table.
If possible, one measure for profile,one measure for Direct and one measure for Target would be greatly appreciated.
My expected output:
| Date | Accrual | Source |
| 01/01/2022 | 1 | Profile |
| 02/01/2022 | 2 | Profile |
| 03/01/2022 | 1 | Direct |
| 04/01/2022 | 1 | Target |
| 05/01/2022 | 1 | Target |
| 06/01/2022 | 2 | Target |
| 07/01/2022 | 1 | Direct |
The main reason for creating this measure to use that in a visual as below:
For our case, we can use month instead of Period
Can you please guide me on this?
PFA sample file in below link:
Thanks in advance
Ahmed lbendlin Ashish_Mathur amitchandak
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.
6 Replies
- lbendlin
Super User
You can do this with a simple COALESCE(Actuals, Target)
- sivarajan21
Post Prodigy
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
- lbendlin
Super User
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.
- Ashish_Mathur
Super User
Hi,
In the Target table as well ensure that there is a third column with the same heading as is there in the first table. In the Query Editor, append the 2 tables.
- sivarajan21
Post Prodigy
Hi Team,
Thanks for all your responses given till now.
As I am not getting any solution, I will close this query.