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
Anonymous
Not applicable

If date is between two dates return value

This looks like a common question on here but I cant seem to find a good solution for my situation.  I'm new to PBI and am trying to understand how DAX works. 

 

I have two tables: Rolling_Calendar and Fiscal_Calendar.  In the Rolling_Calendar table, I would like to add a column that looks at the date column and compares it to the Fiscal_Calendar_StartFiscalMonth date and the Fiscal_Calendar_EndFiscalMonth date and return the FiscalMonth value.  

 

Ive tried using a formula like = IF(Rolling_Calendar_Date) = DatesBetween(Fiscal_Calendar_StartFiscalMonth, Fiscal_Calendar_EndFiscalMonth, Fiscal_Calendar_FiscalMonth, " ").

 

Any suggestions?

Tables.png

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

Hi, @Anonymous 

 

Try to create a measure like below :

__FiscalMonth =
VAR _a =
    SELECTEDVALUE ( 'Rolling_Calendar'[Date] )
RETURN
    CALCULATE (
        MAX ( 'Fiscal_Calendar'[FiscalMonth] ),
        FILTER (
            ALL ( 'Fiscal_Calendar' ),
            'Fiscal_Calendar'[EndFiscalMonth] >= _a
                && _a >= 'Fiscal_Calendar'[StartFiscalMonth]
        )
    )

Result:

v-angzheng-msft_0-1621331577915.jpeg

 

Please refer to the attachment below for details

 

 

Is this the result you want? Hope this is useful to you

Please feel free to let me know If you have further questions

 

Best Regards,
Community Support Team _ Zeon Zheng
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
v-angzheng-msft
Community Support
Community Support

Hi, @Anonymous 

 

Try to create a measure like below :

__FiscalMonth =
VAR _a =
    SELECTEDVALUE ( 'Rolling_Calendar'[Date] )
RETURN
    CALCULATE (
        MAX ( 'Fiscal_Calendar'[FiscalMonth] ),
        FILTER (
            ALL ( 'Fiscal_Calendar' ),
            'Fiscal_Calendar'[EndFiscalMonth] >= _a
                && _a >= 'Fiscal_Calendar'[StartFiscalMonth]
        )
    )

Result:

v-angzheng-msft_0-1621331577915.jpeg

 

Please refer to the attachment below for details

 

 

Is this the result you want? Hope this is useful to you

Please feel free to let me know If you have further questions

 

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

Anonymous
Not applicable

This is great! Thank you @v-angzheng-msft !

Anonymous
Not applicable

hello 

try writing DAX as 

FiscalMonth =
CALCULATE (
    VALUES ( FiscalMonth ),
    FILTER (
        Fiscal_Calendar,
        Rolling_Calendar_Date <= Fiscal_Calendar_StartFiscalMonth
            && Rolling_Calendar_Date >= Fiscal_Calendar_EndFiscalMonth
    )
)
Anonymous
Not applicable

Thanks for your suggestion.  I tried using the formula but the column isnt returning any values.  Ill try some variations of the formula to see if theres something Im missing!

edhans
Super User
Super User

You can use LOOKUPVALUE() but that really would not be good practice here. You are treating DAX like these are Excel spreadsheets, and that isn't how it works. Your best bet would be to merge these two tables in Power Query, then get the relevant column out of it.

But I would ask what is your end goal? You need 1 good date table in the model, not 2 (as a rule) so tell us what you are trying to accomplish here and we can take a fresh look at it. We need data too. Cannot use images as source data.

 

How to get good help fast. Help us help you.

How To Ask A Technical Question If you Really Want An Answer

How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

Yes I guess thats what I'm trying to do but so that I can create a relationship between the budget period and budget table that I have to create.  I tried to put all the information in one table but wasnt able to see how I would be able to create any relationships to other tables.  The budget table has three categories for each fiscal month.  I wasnt going to try and do all three so I was selecting 1 to start with. 

Budget example.JPG

 

My goal is to create a budget category table that will link to a budget period table and calendar table Im currently working on.  These tables will eventually link to our order, customer and item tables. 

(The attached picture is the model Im trying to create based of Matt Allingtons Supercharge Power BI 3rd edition).

 

The calendar and budget tables will allow for us to slice by calendar month and by budget month.  It would also allow for us to include a KPI card to compare current sales to what the monthly budget is.

 

Model.JPG

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.