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
Ghaston
Helper I
Helper I

Calculating the difference between a specific month, and the following months

Hi guys.
This is my first message in the power bi community. 
I'm counting on your help

I need to calculate for each year, the difference between the stock value of Decembre( the last month of the last year), and stock value of all the following months (of the current year). 
here is the link to the Excel file that i'm using.
https://drive.google.com/open?id=1CtnvMq3mpexlESyyVLjbhQZo6H12RmR2

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

Hi@ Ghaston

After my research by your new file,You can use this measure

Column 2 = 
    CALCULATE(
        SUM(
            Data[Val.stk va]),
            FILTER(
                Data,
                Data[Groupe marchandises]=EARLIER(Data[Groupe marchandises])&&Data[Year]=EARLIER(Data[Year])&&Data[Month]=EARLIER(Data[Month])))-



CALCULATE(
                    SUM(
                        Data[Val.stk va]),
                        FILTER(
                            Data,
                            Data[Groupe marchandises]=EARLIER(Data[Groupe marchandises])&&Data[Year]+1=EARLIER(Data[Year])&&Data[Month]=12))

Result:

1.png

Here is demo, please try it

https://www.dropbox.com/s/oe52n3yaehet74z/CSP%20-%20Cartographie%20stock%20hors%20PF%20-%20MSLB%20Ne...

 

 

Best Regards,

Lin

Community Support Team _ Lin
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

5 REPLIES 5
Anonymous
Not applicable

I need to get the difference between the count of values in a column, this month and the previous month   

v-lili6-msft
Community Support
Community Support

Hi@ Ghaston

After my research by your new file,You can use this measure

Column 2 = 
    CALCULATE(
        SUM(
            Data[Val.stk va]),
            FILTER(
                Data,
                Data[Groupe marchandises]=EARLIER(Data[Groupe marchandises])&&Data[Year]=EARLIER(Data[Year])&&Data[Month]=EARLIER(Data[Month])))-



CALCULATE(
                    SUM(
                        Data[Val.stk va]),
                        FILTER(
                            Data,
                            Data[Groupe marchandises]=EARLIER(Data[Groupe marchandises])&&Data[Year]+1=EARLIER(Data[Year])&&Data[Month]=12))

Result:

1.png

Here is demo, please try it

https://www.dropbox.com/s/oe52n3yaehet74z/CSP%20-%20Cartographie%20stock%20hors%20PF%20-%20MSLB%20Ne...

 

 

Best Regards,

Lin

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

Hi @v-lili6-msft
Thanks for the help
Your solution works exactly as i wanted !  

Best regards
Ghaston

v-lili6-msft
Community Support
Community Support

Hi@ Ghaston

After my research, you can do these follow my steps like below:

Step1:

Add two columns

Year = YEAR(Data[Mois])
Month = MONTH(Data[Mois])

Step2:

Add the calculate column

Column =
IF (
    Data[Month] = 12,
    CALCULATE (
        SUM ( Data[Stock] ),
        FILTER (
            Data,
            Data[Type d'article] = EARLIER ( Data[Type d'article] )
                && Data[Year] = EARLIER ( Data[Year] )
                && Data[Month] = 12
        )
    )
        - CALCULATE (
            SUM ( Data[Stock] ),
            FILTER (
                Data,
                Data[Type d'article] = EARLIER ( Data[Type d'article] )
                    && Data[Year]
                        = EARLIER ( Data[Year] ) + 1
            )
        )
)

Result:

7.png

Here is demo ,please try it

https://www.dropbox.com/s/19k5ioep8keqj8r/CSP%20-%20Cartographie%20stock%20hors%20PF%20-%20MSLB.pbix...

 

 

 

Best Regards,

Lin

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

Hi @v-lili6-msft 
thanks for your help ! 
i appreciate it 
Actually, the result should be : 
January(2018) - December(2017)
February(2018) - December(2017)
Mars(2018) - December(2017)
excetera
and in 2019, the result should be : 
January(2019) - December(2018)
February(2019) - December(2018)
Mars(2019) - December(2018) 
excetera

So, for exemple, when i select " the month January "  in the filter; i need to see the "stock value of January(2018) - stock value of december(2017).  
Juste to make sur that the new code works well : For the "AAAA Sable", when we select 01/01/2018, the result should be : 25 687.44(stock value in January) -28 493.57(stock value in december) = -2 806.13.

I send u back the file with the small modification that i made to your code : ( i replaced the column "stock" with the colown "Val.Stck va". And also replaced "type d'article" with "groupe de marchandise". And i put the date in a filter. 

https://drive.google.com/open?id=1CtnvMq3mpexlESyyVLjbhQZo6H12RmR2

Hope you can help me out 

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.