Forum Discussion
Grouping for multiple calculation (sum and substract) with respect to categories
- Anonymous2 years ago
Hi Bhatt23
Based on your description, if there are no calculation group, will they shold be sum together? such as the BN101.
I create the following sample based on the understanding I have described, you can refer it.
Sample data is the same as you provided.
Create the following measures.
Calculation_group = MAXX ( FILTER ( ALLSELECTED ( 'Formula with mapping' ), [Division] IN VALUES ( 'Data'[Division] ) && [Subdivision] IN VALUES ( 'Data'[Subdivision] ) ), [Calculation based on DPID which represent Subdivision] )Left_calculation = LEFT([Calculation_group],SEARCH(")",[Calculation_group],,BLANK()))Right_calculation = RIGHT([Calculation_group],LEN([Calculation_group])-SEARCH(")",[Calculation_group],,BLANK()))Sum_calculation = VAR a = SUMX ( FILTER ( ALLSELECTED ( 'Data' ), [Division] IN VALUES ( 'Data'[Division] ) && [Subdivision] IN VALUES ( 'Data'[Subdivision] ) && CONTAINSSTRING ( [Left_calculation], [DPID] ) ), [VALUE] ) VAR b = SUMX ( FILTER ( ALLSELECTED ( 'Data' ), [Division] IN VALUES ( 'Data'[Division] ) && [Subdivision] IN VALUES ( 'Data'[Subdivision] ) && CONTAINSSTRING ( [Right_calculation], [DPID] ) ), [VALUE] ) RETURN SWITCH ( TRUE (), [Calculation_group] = BLANK (), SUMX ( FILTER ( ALLSELECTED ( 'Data' ), [Division] IN VALUES ( 'Data'[Division] ) && [Subdivision] IN VALUES ( 'Data'[Subdivision] ) ), [VALUE] ), [Left_calculation] = BLANK (), b, [Left_calculation] <> BLANK (), a - b )Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Yolo,
I tested and it failed.
I forgot to mention few important things:-
The data table consist of Date and time column which is every mins or hours data and the number of rows are more than 200K.
So when I tested this with actual data to see the trend via bar chart it failed with error visual has exceeded the available resources.
Sorry but I should have mentioned these points in the beginning.
So the data table is created after merging the formula with mapping table to data that means data table as separate only consist of DPID, Value and date/time however merging it with Mapping table via DPID gives me the main data table that is as below on which I did calculation and it failed to show me correct result.
| DPID | Division | Subdivision | Value | Date and time |
| 9680 | A | API 1 | 16.493 | 2024-04-22T12:15:38.2500000 |
| 9692 | A | API 1 | 16.508 | 2024-04-24T02:38:43.7600000 |
| 9677 | A | API 1 | 16.512 | 2024-04-24T12:38:47.7500000 |
| 9706 | S | BN101 | 16.519 | 2024-04-25T07:00:18.2500000 |
| 9711 | A | API 1 | 16.521 | 2024-04-25T12:45:46.7500000 |
| 9709 | P | BR1 | 16.525 | 2024-04-25T23:38:59.7500000 |
| 9689 | P | BR2 | 16.535 | 2024-04-27T06:09:10.5400000 |
| 9686 | P | APA 1 | 16.54 | 2024-04-28T10:39:20.5100000 |
| 9691 | P | APA 1 Test | 16.544 | 2024-04-29T03:09:26.5100000 |
| 9672 | P | APA 1 Test | 16.552 | 2024-04-30T00:31:00.2400000 |
| 9701 | N | Not known | 16.554 | 2024-04-30T08:09:38.2300000 |
| 9676 | N | Not known | 16.557 | 2024-04-30T17:39:41.2300000 |
| 9710 | P | APA 1 | 16.568 | 2024-05-02T10:39:56.9500000 |
| 9674 | P | APA 1 | 16.574 | 2024-05-03T07:15:27.4500000 |
| 9703 | A | API Endurance | 16.578 | 2024-05-03T19:40:08.9600000 |
| 9687 | P | APA 1 Test | 16.579 | 2024-05-04T18:40:16.9700000 |
| 9678 | P | APA 1 | 16.58 | 2024-05-05T03:15:48.4800000 |
| 9670 | P | APA 1 | 16.58 | 2024-05-05T09:10:21.9800000 |
| 9671 | P | APA 1 Test | 16.58 | 2024-05-05T12:10:22.9900000 |
| 9702 | A | API Endurance | 16.585 | 2024-05-06T12:40:31.7700000 |
| 9688 | A | API Endurance | 16.588 | 2024-05-06T21:40:34.7500000 |
| 9675 | p | APA 1 | 16.598 | 2024-05-08T03:40:47.1000000 |
| 9679 | F | CR1 | 16.603 | 2024-05-08T21:00:47.3700000 |
| 9697 | F | CR2 | 16.605 | 2024-05-09T20:11:02.0100000 |
| 9699 | S | AID_ASC | 16.609 | 2024-05-12T09:41:25.2200000 |
| 9708 | S | AID_ASC | 16.609 | 2024-05-12T13:11:26.2200000 |
| 9705 | P | APA 2 | 16.612 | 2024-05-13T09:41:33.2200000 |
| 9693 | P | APA 2 | 16.613 | 2024-05-13T12:11:34.2200000 |
| 9673 | P | APA 2 | 16.616 | 2024-05-13T20:00:25.4700000 |
| 9704 | P | APA 2 | 16.629 | 2024-05-15T09:16:19.4800000 |
| 9694 | F | APF End Test | 16.636 | 2024-05-16T01:45:30.5000000 |
| 9700 | F | APF End Test | 16.643 | 2024-05-16T19:42:03.2600000 |
| 9682 | Y | YR1 | 16.643 | 2024-05-16T21:42:04.2500000 |
| 9696 | Y | YR2 | 16.649 | 2024-05-17T10:12:09.2500000 |
| 9690 | SAS | P & P + Warmtepomp | 16.652 | 17-05-2024 21:16:15 |
| 9685 | SAS | HVAC EB A15 | 16.653 | 2024-05-18T16:12:19.2500000 |
| 9683 | F | APF Labo | 16.653 | 2024-05-18T23:42:22.2500000 |
| 9684 | SAS | MT111 | 16.664 | 2024-05-22T14:01:13.1400000 |
| 9695 | SAS | MT112 | 1.5388 | 2024-04-30T12:39:40.2300000 |
| 9698 | SAS | MT110 | 1.5388 | 2024-04-30T19:09:42.2300000 |
| 9707 | F | APF Labo | 1.5388 | 2024-04-30T23:39:43.2300000 |
| 9681 | M | HR1 | 1.539 | 2024-05-02T08:39:56.9500000 |
| 9748 | SMP | HR2 | 1.539 | 2024-05-02T09:09:56.9500000 |
| 9747 | SMP | HR3 | 1.5392 | 2024-05-02T16:39:58.9500000 |
| 9753 | SMP | HR4 | 1.5397 | 2024-05-04T10:40:13.9600000 |
| 9752 | SMP | HR8 | 1.5397 | 2024-05-04T16:10:15.9700000 |
| 9751 | SMP | HR11 | 1.5397 | 2024-05-05T14:40:23.9800000 |
| 9750 | SMP | HR12 | 1.5397 | 2024-05-05T19:10:25.9800000 |
| 9746 | SMP | HR14 | 1.5397 | 2024-05-06T02:40:28.9900000 |
| 9749 | SMP | HR12 | 1.5415 | 2024-05-09T07:40:57.1300000 |
| 9693 | A | API 2 | 1.5418 | 2024-05-12T18:41:28.2200000 |
| 9673 | A | API 2 | 1.542 | 2024-05-13T09:41:33.2200000 |
| 9680 | A | API 1 | 1.542 | 2024-05-13T18:11:36.2200000 |
| 9692 | A | API 1 | 1.5433 | 2024-05-17T17:42:11.2500000 |
| 9677 | A | API 1 | 1.5433 | 2024-05-18T09:42:17.2500000 |
| 9706 | S | BN101 | 1.5433 | 2024-05-19T19:42:29.2500000 |
| 9711 | A | API 1 | 1.5433 | 2024-05-20T02:42:31.2600000 |
| 9709 | P | BR1 | 1.5433 | 20-05-2024 11:42:35 |
| 9689 | P | BR2 | 1.5433 | 2024-05-20T20:12:38.0100000 |
| 9686 | P | APA 1 | 1.5448 | 2024-05-22T09:12:52.6400000 |
| 9691 | P | APA 1 Test | 1.545 | 2024-05-22T21:42:56.6400000 |
| 9672 | P | APA 1 Test | 3.9331 | 2024-04-23T08:08:36.7500000 |
| 9701 | N | Not known | 3.9342 | 2024-04-24T08:08:45.7500000 |
| 9676 | N | Not known | 3.9352 | 2024-04-25T15:38:56.7500000 |
| 9710 | P | APA 1 | 3.9363 | 2024-04-26T23:39:08.7700000 |
| 9674 | P | APA 1 | 3.9365 | 2024-04-27T10:39:12.5100000 |
| 9703 | A | API Endurance | 3.9384 | 2024-04-30T05:09:37.2300000 |
| 9687 | P | APA 1 Test | 3.9401 | 2024-05-01T23:15:16.9800000 |
| 9678 | P | APA 1 | 3.9424 | 2024-05-04T11:40:14.9600000 |
| 9670 | P | APA 1 | 3.9424 | 2024-05-04T22:40:18.9800000 |
| 9671 | P | APA 1 Test | 3.944 | 2024-05-06T19:40:34.7500000 |
| 9702 | A | API Endurance | 3.9446 | 2024-05-07T07:40:38.7500000 |
| 9688 | A | API Endurance | 3.9463 | 2024-05-08T08:45:31.1000000 |
| 9675 | p | APA 1 | 3.9466 | 2024-05-08T15:10:51.1000000 |
| 9679 | F | CR1 | 3.947 | 2024-05-11T01:41:12.0100000 |
| 9697 | F | CR2 | 3.9497 | 2024-05-14T00:41:39.2300000 |
| 9699 | S | AID_ASC | 3.9506 | 2024-05-14T13:11:43.2300000 |
| 9708 | S | AID_ASC | 3.9514 | 2024-05-15T01:41:47.2300000 |
| 9705 | P | APA 2 | 3.954 | 2024-05-16T11:00:43.4800000 |
| 9693 | P | APA 2 | 3.955 | 2024-05-17T04:42:07.2500000 |
| 9673 | P | APA 2 | 3.9556 | 2024-05-17T12:42:09.2500000 |
| 9704 | P | APA 2 | 3.9559 | 2024-05-17T17:12:11.2500000 |
| 9694 | F | APF End Test | 3.9563 | 2024-05-21T09:42:44.6300000 |
| 9700 | F | APF End Test | 3.9575 | 2024-05-22T02:12:50.6400000 |
| 9682 | Y | YR1 | 3.9587 | 2024-05-22T18:42:55.6400000 |
| 9696 | Y | YR2 | 39.766 | 23-04-2024 08:31:05 |
| 9690 | SAS | P & P + Warmtepomp | 39.766 | 23-04-2024 08:31:05 |
| 9685 | SAS | HVAC EB A15 | 39.777 | 2024-04-24T07:38:45.7500000 |
| 9683 | F | APF Labo | 39.777 | 2024-04-24T07:38:45.7500000 |
| 9684 | SAS | MT111 | 39.783 | 2024-04-24T20:01:16.5000000 |
| 9695 | SAS | MT112 | 39.783 | 2024-04-24T20:01:16.5000000 |
| 9698 | SAS | MT110 | 39.787 | 2024-04-25T08:15:25.5000000 |
| 9707 | F | APF Labo | 39.787 | 2024-04-25T08:15:25.5000000 |
| 9681 | M | HR1 | 39.792 | 25-04-2024 15:01:06 |
| 9748 | SMP | HR2 | 39.792 | 25-04-2024 15:01:06 |
| 9747 | SMP | HR3 | 39.813 | 2024-04-28T03:09:18.5100000 |
| 9753 | SMP | HR4 | 39.813 | 2024-04-28T03:09:18.5100000 |
| 9752 | SMP | HR8 | 39.816 | 2024-04-28T13:45:26.7600000 |
| 9751 | SMP | HR11 | 39.816 | 2024-04-28T13:45:26.7600000 |