Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
OscarSuarez10
Helper III
Helper III

Need to substract production of a same product at different dates

Hi, I need to substract the inital production and the final production of one product at different years,

For example for the product AK01 need to substract the production (WOPT) at the last date of 2019 - the production (WOPT) at the fist date of 2019, the I have to do the same for 2020, 2021 2022 ... The table has other products and I have to do the same thing for each product

 

Diferencial pozos pregunta.PNG

1 ACCEPTED SOLUTION

Hi @OscarSuarez10 

If your requirement is:

for 2020, you need the difference:

[data_of_first_date_of_2020]- [data_of_last_date_of_2019]
 
You could create a column
year = YEAR([TIME])
Create measures
data_of_first_date_per_year =
VAR min_date =
    CALCULATE (
        MIN ( Sheet4[TIME] ),
        ALLEXCEPT ( Sheet4, Sheet4[OBJECT ], Sheet4[year] )
    )
RETURN
    CALCULATE (
        SUM ( Sheet4[PRODUCTION] ),
        FILTER (
            ALLEXCEPT ( Sheet4, Sheet4[OBJECT ], Sheet4[year] ),
            [TIME] = min_date
        )
    )


data_of_last_date_per_year =
VAR max_date =
    CALCULATE (
        MAX ( Sheet4[TIME] ),
        ALLEXCEPT ( Sheet4, Sheet4[OBJECT ], Sheet4[year] )
    )
RETURN
    CALCULATE (
        SUM ( Sheet4[PRODUCTION] ),
        FILTER (
            ALLEXCEPT ( Sheet4, Sheet4[OBJECT ], Sheet4[year] ),
            [TIME] = max_date
        )
    )
5.png
 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Stachu
Community Champion
Community Champion

I don't really get what you're trying to achieve. Can you paste the same table with column that would show the output (as copiable table so I can put it in PowerBI and try calculating myself)



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Hello This the output that I wan to achieve:

 

EXAMPLE.jpg

Isn't that's just a simple sum? I cannot type all the data manually, can you post it in theformat as below (just copy from Excel) into the reply window

Column1 Column2
A 2
B 2.1
C 3


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

No, I need to calculate de prduction of each object per year, as you can see in the Output columns (red)

 

TIMEOBJECT PRODUCTION                  OUTPUT
30/05/2019OB13,38E+11YEAROBJECTDIFERENTIAL PRODUCTION PER YEAR
29/06/2019OB13,39E+112019OB1-3,032E+11
29/07/2019OB1341000000002020OB120000000000
28/08/2019OB1343000000002019CB19207788
27/09/2019OB13,44E+112020CB19141234
27/10/2019OB13,46E+11   
26/11/2019OB134800000000   
26/12/2019OB13,5E+11   
25/01/2020OB13,51E+11   
24/02/2020OB13,53E+11   
25/03/2020OB13,55E+11   
24/04/2020OB13,57E+11   
24/05/2020OB13,58E+11   
23/06/2020OB136000000000   
23/07/2020OB13,62E+11   
22/08/2020OB13,64E+11   
21/09/2020OB13,66E+11   
21/10/2020OB13,68E+11   
20/11/2020OB136900000000   
20/12/2020OB13,71E+11   
31/03/2019CB19349107   
30/04/2019CB19371902   
30/05/2019CB19394911   
29/06/2019CB19417173   
29/07/2019CB19440726   
28/08/2019CB19465046   
27/09/2019CB19488512   
27/10/2019CB19511962   
26/11/2019CB19534353   
26/12/2019CB19556895   
25/01/2020CB19579036   
24/02/2020CB19600047   
25/03/2020CB19621087   
24/04/2020CB19641970   
24/05/2020CB19662074   
23/06/2020CB19682201   
23/07/2020CB19701256   
22/08/2020CB19720270   

Hi @OscarSuarez10 

If your requirement is:

for 2020, you need the difference:

[data_of_first_date_of_2020]- [data_of_last_date_of_2019]
 
You could create a column
year = YEAR([TIME])
Create measures
data_of_first_date_per_year =
VAR min_date =
    CALCULATE (
        MIN ( Sheet4[TIME] ),
        ALLEXCEPT ( Sheet4, Sheet4[OBJECT ], Sheet4[year] )
    )
RETURN
    CALCULATE (
        SUM ( Sheet4[PRODUCTION] ),
        FILTER (
            ALLEXCEPT ( Sheet4, Sheet4[OBJECT ], Sheet4[year] ),
            [TIME] = min_date
        )
    )


data_of_last_date_per_year =
VAR max_date =
    CALCULATE (
        MAX ( Sheet4[TIME] ),
        ALLEXCEPT ( Sheet4, Sheet4[OBJECT ], Sheet4[year] )
    )
RETURN
    CALCULATE (
        SUM ( Sheet4[PRODUCTION] ),
        FILTER (
            ALLEXCEPT ( Sheet4, Sheet4[OBJECT ], Sheet4[year] ),
            [TIME] = max_date
        )
    )
5.png
 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

this would work as a calculated column, you can then sum it with time aggregate - is it fine or do you need a measure?

Column =
VAR __Object = 'Table'[OBJECT ]
VAR __Year = YEAR ( 'Table'[IME] )
VAR __FirstPeriodInYear =
    CALCULATE (
        MIN ( 'Table'[IME] ),
        FILTER (
            ALL ( 'Table' ),
            YEAR ( 'Table'[IME] ) = __Year
                && 'Table'[OBJECT ] = __Object
        )
    )
VAR __LastPeriodInYear =
    CALCULATE (
        MAX ( 'Table'[IME] ),
        FILTER (
            ALL ( 'Table' ),
            YEAR ( 'Table'[IME] ) = __Year
                && 'Table'[OBJECT ] = __Object
        )
    )
VAR __FirstPeriodProduction =
    CALCULATE (
        SUM ( 'Table'[PRODUCTION] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[IME] = __FirstPeriodInYear
                && 'Table'[OBJECT ] = __Object
        )
    )
VAR __LastPeriodProduction =
    CALCULATE (
        SUM ( 'Table'[PRODUCTION] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[IME] = __LastPeriodInYear
                && 'Table'[OBJECT ] = __Object
        )
    )
RETURN
    IF (
        'Table'[IME] = __LastPeriodInYear,
        __LastPeriodProduction - __FirstPeriodProduction,
        BLANK ()
    )


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors