Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
ChihiroWa
Frequent Visitor

DATESBETWEEN function error

Hi, I hope someone help me with a DATESBETWEEN function error.

 

 Prepared tables are like below:

 Table A : a period of item production

CountrySegmentsItem namePeriod - startPeriod - end
JapanAxxx2013/1/12015/12/31
JapanAyyy2010/1/12020/12/31
JapanBzzz2020/1/12025/12/31
IndiaAaaa2018/1/12020/12/31
IndiaCbbb2040/1/12045/12/31
IndonesiaBccc2030/1/12035/12/31
IndonesiaCddd2025/1/12030/12/31
・・・・・・・・・・・・・・・

 

 Table B : global market volume

CountyCYVolume
Japan20201000000
Japan20211200000
Indonesia20202000000
・・・・・・・・・

 

What I want to do is :  changing x-axis of a graph by selecting country

e.g. Japan -> from 2010 to 2025

・a slicer

ChihiroWa_1-1691549015809.png

 

・a gragh

ChihiroWa_0-1691548979439.png

 

 

What I tried:  DATESBETWEEN function

period for x-axis = DATESBETWEEN(TableB'[CY],FIRSTDATE('TableA'[Period - start]),LASTDATE('TableA'[Period - end]))
 
error : 
ChihiroWa_2-1691549665943.png

 

Thanks,

Chihiro

 
4 REPLIES 4
danextian
Super User
Super User

HI @ChihiroWa ,

 

DATESBETWEEN is a table function and will return a table of dates if used in creating a calculated table. If used in a measure, it is to filter an aggregation and is to be used together with CALCULATE. The correct syntax is something like

=
CALCULATE (
    [Measure],
    DATESBETWEEN (
        TableB,
        FIRSTDATE ( 'TableA'[Period - start] ),
        LASTDATE ( 'TableA'[Period - end] )
    )
)

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

@danextian ,Thanks a lot!

I found using DATESBETWEEN is not a good way to solve my problem.

If you have, could you tell me some other better ways ?

The answer really depends on your use case but information provided isnt enough to propose more appropriate one. What is the data used in your area chart? Is that volume? If so, your field pane should look something like this.

 

danextian_0-1691551947198.png

Also, the formula below will not even return a table of dates as you are comparing a year against a date.

=
DATESBETWEEN (
    'TableB'[CY],
    FIRSTDATE ( 'TableA'[Period - start] ),
    LASTDATE ( 'TableA'[Period - end] )
)

Just DATESBETWEEN should be something like this. In your example, CY is year.

DATESBETWEEN(<Dates>, <StartDate>, <EndDate>)

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Yes, the area chart shows volume, and field pane looks something like that.

Actually, Table B has thousand of rows, sorry for making confuse you.

 

As to CY, I prepared 'CY[date]' to recognize CY as a date.

CY[date] = 'TableB'[CY])&"/01/01"

 

 

 

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.