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
vvza
New Member

Need to write proper query which return previous month if today is >= 10 day

Hi!

I have a dynamic graph which show me dates in period from January to July


I need to write query in DAX which add autamatically august dates in my graph if today is >=10,

for instance, today is 6 September, so my graph will show me all dates between 1 January and 31 July, but

if the day of current month (in our case is September) is >= 10 (for instance today is 11 September), so query automatically have to add previous month dates (august) 
So,  I wrote something like that:
Column = if(day(TODAY()) >= 10, IF('DT'[Date] < TODAY()-10,1,MAX(EOMONTH(TODAY(),-2),0))) - but it doesnt return what I expect

but Im not sure, should it be like new column or new measure? Because I will use it like filter for my dashboards...

So, the logic of the query look pretty simple, if day of today is >= 10, then add previous month to graph (from start of the year (1 January)till the last day of previous month (31 August), 
in other case - show me all dates till the current month - 2 (so, all dates in range between 1 January and 31 July)
This filter would help me to avoid add manualy every new month to my graph... I would like to write query which do it automatically

Please, share me your opinions and advices.


Many thanks in advance!

@amitchandak @daXtreme 

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @vvza,

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Аннотация 2022-09-07 103148.png

Can not add file (.pbix) dont kow why(The file type (".pbix) is not supported."-that`s the reason probably), but there is simple graph which show dates for 7 month, so I would like create a filter what add next month automatically, because now I need to choose after 10th September previous month manually on my filter (you can see it on this screen, month number 8 = August). So, if today day is >=10 then add august to my graph, otherwise show all dates till 31 july (last day of 2 month ago from today)
I managed to write something like this 

if(day(TODAY()) >= 10,EOMONTH(TODAY(),-1)+0,EOMONTH(TODAY(),-2)+0)
but it didnt work in way what I want, so try this one
if(day(TODAY()) >= 10,DATEADD('DT'[Date],-1, MONTH),DATEADD('DT'[Date],-2, MONTH))
but still didnt get what I want, mat be this part would work
DATEADD((DATE(YEAR(TODAY()), MONTH(TODAY()), 1)), -1, MONTH)
but still not the result Im looking for. 
@v-shex-msft Could you help me please, to write the query that will add a previous month to my graph after every 10th day of the current month, otherwise, all the dates till last day of 2 month ago

HI @vvza,

You can try to use the following measure formula to calculate the rolling two-month amount based on the current date.
if the current system date is larger than the 10th, the current month's records will be included in the cumulative calculation; if not, the rolling calculation will calculate until the previous month's end.

formula =
IF (
    DAY ( TODAY () ) >= 10,
    CALCULATE (
        SUM ( Table[Amount] ),
        FILTER (
            ALLSELECTED ( Table ),
            [Date]
                >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 2, DAY ( TODAY () ) )
        )
    ),
    CALCULATE (
        SUM ( Table[Amount] ),
        FILTER (
            ALLSELECTED ( Table ),
            [Date]
                >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 2, DAY ( TODAY () ) )
                && [Date]
                    <= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ) - 1
        )
    )
)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
vvza
New Member

@Ashish_Mathur would like to know your opinion, please

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.