cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
GA1993
Helper II
Helper II

Difference of values for the last 3 months

Please how do I translate this into a DAX formula??

 

GA1993_1-1631152172305.png

 

 

=IF((G4-F4-E4)<=0,1,0)*IF((G5-F5-E5)<=0,1,0)*IF((G6-F6-E6)<=0,1,0)

 

 

My goal is to subtract the current month and the previous 2 months then apply the corresponding multiplication as indicated.

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@GA1993 , for this we need to what is raw data and what is column on row.

 

productX can help. But if have months as column , then we can have

 

productX(Table, [Aug-21] -[Jul-21]-[Jun-21])

 

If not then we create a measure and we need a context to run that like

 

productX(values(Table[ID]) , CALCULATE(SUM(Table[Value]),DATESMTD('Date'[Date]))

                    -CALCULATE(SUM(Table[Value]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

                   -CALCULATE(SUM(Table[Value]),DATESMTD(dateadd('Date'[Date],-2,MONTH))) )

 

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || 50+Power Query List Functions : Learn Power Query List
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@GA1993 , for this we need to what is raw data and what is column on row.

 

productX can help. But if have months as column , then we can have

 

productX(Table, [Aug-21] -[Jul-21]-[Jun-21])

 

If not then we create a measure and we need a context to run that like

 

productX(values(Table[ID]) , CALCULATE(SUM(Table[Value]),DATESMTD('Date'[Date]))

                    -CALCULATE(SUM(Table[Value]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

                   -CALCULATE(SUM(Table[Value]),DATESMTD(dateadd('Date'[Date],-2,MONTH))) )

 

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || 50+Power Query List Functions : Learn Power Query List
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

Is there a way to do it by subtracting the current and previous month?

 

I am trying to reuse your code but I keep getting this error below... 

GA1993_0-1631227595259.png

 

The formula on excel is =IF((AW9-AW8)<=0,1,0)

 

and my data should be..

GA1993_1-1631227390637.png

 

Please your help would be really appreciated!!

 

I was able to make it work!! Thank you so much!!

This is how it's supposed to look like..

 

GA1993_1-1631198335935.png

 

 

 

=IF((AQ9-AQ8-AQ7)<=0,1,0)*IF((AR9-AR8-AR7)<=0,1,0)*IF((AS9-AS8-AS7)<=0,1,0)

 

AQ = Unauthorized Access Infraction

AR = Loss of AirPro Assets Infraction

AS = Breach in Security Protocol Infraction

Helpful resources

Announcements
September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Show episode 9

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 26

New Date - Check it Out!

Mark your calendars and join us on Thursday, October 6 at 11a PDT for a great session with Ted Pattison!

Top Solution Authors
Top Kudoed Authors