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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
miroslav_umlauf
New Member

Datesbetween or Calculate after import from Excel to PBI desktop doesn't work

Hi all, already spent hours finding an error, but if it works in classic Excel PowerPivot, then after import until update, it must be a bug ... Or? Is there anything wrong the syntax of the formula bellow?

PowerBI desktop says: The syntax for 'CALCULATE' is incorrect.

The relationship between Calendar and Orders is ok.

 

Customers last 7 days:=CALCULATE ( [Unique customers];
            DATESBETWEEN( Calendar[Date];
                                       CALCULATE ( LASTDATE( Orders[ORDER DATE] ); ALL(Orders))-7;
                                       CALCULATE ( LASTDATE( Orders[ORDER DATE] );ALL(Orders))
                                     )
)

1 ACCEPTED SOLUTION
ALeef
Resolver II
Resolver II

Try:

 

UniqueLast7 = CALCULATE(DISTINCTCOUNT(Orders[CustomerID]), DATESBETWEEN (Orders[Order Date], (NOW()-7), NOW())

 

Assuming that you have CustomerID in the Orders table, along with an Order Date.  This should count the number of distinct customer IDs in the Orders table, between the dates 7 days ago and now.  

 

This will include a timestamp, assuming it is a full date-time field, so if you run this at 8am on monday, an order places at 7am last monday would be excluded using the NOW function.  Hopefully that helps - unless I'm missing the question, you shouldn't have to nest CALCULATEs to get the information you want.

View solution in original post

2 REPLIES 2
ALeef
Resolver II
Resolver II

Try:

 

UniqueLast7 = CALCULATE(DISTINCTCOUNT(Orders[CustomerID]), DATESBETWEEN (Orders[Order Date], (NOW()-7), NOW())

 

Assuming that you have CustomerID in the Orders table, along with an Order Date.  This should count the number of distinct customer IDs in the Orders table, between the dates 7 days ago and now.  

 

This will include a timestamp, assuming it is a full date-time field, so if you run this at 8am on monday, an order places at 7am last monday would be excluded using the NOW function.  Hopefully that helps - unless I'm missing the question, you shouldn't have to nest CALCULATEs to get the information you want.

Greg_Deckler
Community Champion
Community Champion

The semi-colons do not look correct, shouldn't they be commas or is there a language pack involved.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors