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
dsabsi
Advocate I
Advocate I

IF formula with dates and sum with months

Hi Guys, 

 

I'm fairly new to Power BI and my DAXX knowledge is very low, so please bear with me. 

I'm trying to combine an IF formula with dates and with months, and i've searched the PB community but couldn't find the answer anywhere.

Month column: DIM_DATE[MONTHNAME]

 

I want to create a filter in which I can create a sum IF formula. 

If it's 12 november, include the months januari till october from 2017

If it's 13 december, include the months januari till november from 2017

if it's 7 january 2018, include all the months from januari till december 2018. 

 

I started like: if(today()=DATE(2017;11;8);count(DIM_DATE[MONTHNAME]) this but I can't find the formula which states count(januari till october from 2017)

 

With this formula, I can create a filter which filters my financial records so that it shows the SUM after a certain period.

 

Can anyone please help a brother out? 

 

Cheers, 

DSabsi

 

 

 

1 ACCEPTED SOLUTION

Perhaps try something like this:

 

Measure = SWITCH(TODAY(),
                DATE(2017,11,8),SUMX(FILTER('Calendar',MONTH([Date])>=1 && MONTH([Date]<=10)),[Column]),
                DATE(2018,1,3),SUMX(FILTER('Calendar',MONTH([Date])>=1 && MONTH([Date]<=12)),[Column]),
                BLANK())

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Do the specific days matter or is it just based upon what month today happens to be in? Also, what are we counting here? Just the number of days?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @MSMPekowski,

 

The specific days matter, because I want to check what the total outstanding amount is after a certain period. 

This had to do with the fact that after these periods, certain periods are declared. 

 

So if its 8 november, sum of january till october from 2017. 

If it's 3 january 2018, sum januari till december from 2017

If it's 8 february 2018, sum januari 2017 till january 2018

if it's 8 march 2018, sum january 2017 till february 2018

if it's 5 april 2018, sum january 2017 till march 2018

if it's 10 may 2018, sum january 2017 till april 2018. 

 

The above dates are actually what I want to create in this formula. 

 

I really appreciate your swift response and I hope you can provide me with the answer to this @Greg_Deckler

 

Cheers, 

 

Dsabsi

 

Perhaps try something like this:

 

Measure = SWITCH(TODAY(),
                DATE(2017,11,8),SUMX(FILTER('Calendar',MONTH([Date])>=1 && MONTH([Date]<=10)),[Column]),
                DATE(2018,1,3),SUMX(FILTER('Calendar',MONTH([Date])>=1 && MONTH([Date]<=12)),[Column]),
                BLANK())

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @dsabsi

 

Try this DAX measure. Modify Table and Field Names according to your case

MySum =
CALCULATE (
  SUM ( Table1[Amount] ),
  FILTER (
    ALL ( Table1 ),
    Table1[Dates]>= 01 / 01/ 2017
    && Table1[Dates]
   <= DATE ( YEAR ( VALUES ( Table1[Dates] ) ), MONTH ( VALUES ( Table1[Dates] ) ) - 1, 31 )
    )
)


See the attached file Download file


Regards
Zubair

Please try my custom visuals

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.