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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Jean_Ferro
Helper I
Helper I

Getting unexpected exception with measure

Hello everyone!

I am creating this measure that works as needed only if I keep the date fixed like DATE(2024, 6, 10), if I try to make the date dynamic using a measure that returns the greatest date chosen by the user in the calendar like this:

maxx(dCalendar,[Date])

I get the error "unexpected exception"


SUMX(
ADDCOLUMNS(
SUMMARIZE(
FILTER(
fStock,
fStock[DTABASE] <= DATE(2024, 6, 10)
),
fStock[PRODUCT_CODE],
fStock[BRANCH],
"MaxDate", MAX(fStock[DTABASE])
),
"Cost",
CALCULATE(
MAX(fStock[COST]),
FILTER(
fStock,
fStock[DTABASE] = [MaxDtaEntradaSaida] &&
fStock[PRODUCT_CODE] = EARLIER(fStock[PRODUCT_CODE]) &&
fStock[BRANCH] = EARLIER(fStock[BRANCH])
)
)
),
[Cost]
)


Jean_Ferro_0-1718630985675.png

 

8 REPLIES 8
Greg_Deckler
Community Champion
Community Champion

@Jean_Ferro What about just MAX('dCalendar'[Date])

or:

Measure = 
VAR __Date = MAX('dCalendar'[Date])
VAR __Result = 
SUMX(
ADDCOLUMNS(
SUMMARIZE(
FILTER(
fStock,
fStock[DTABASE] <= __Date
),
fStock[PRODUCT_CODE],
fStock[BRANCH],
"MaxDate", MAX(fStock[DTABASE])
),
"Cost",
CALCULATE(
MAX(fStock[COST]),
FILTER(
fStock,
fStock[DTABASE] = [MaxDtaEntradaSaida] &&
fStock[PRODUCT_CODE] = EARLIER(fStock[PRODUCT_CODE]) &&
fStock[BRANCH] = EARLIER(fStock[BRANCH])
)
)
),
[Cost]
)
RETURN
  __Result


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...

Unfortunately the same unexpected exception error, if I change it to DATE(2024,6,5) for example it works, but I need it to be dynamic.

The measure to return the greatest date seems correct to me:



GreatestDataStock = maxx(dCalendar,[Date])

Jean_Ferro_0-1718633078929.png

 

@Jean_Ferro Any chance you can post a link to the file? Otherwise it's really hard to understand what is going on here.



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...

I was preparing a file to upload with just the information to reproduce the error but when I tested it on this test file it worked.

In my production development I use two databases communicating by direct query sharing 1 calendar, when I separated the calendars leaving one for each database it worked.

I'm going to use it like this for now, but I would like to find a way to use a calendar for both databases without the error.

@Jean_Ferro You may want to play around with privacy level settings then. Depending on those settings, some cross query/source queries aren't allowed.



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...

With this method, i change privacy level for this on all file involved:

Is here?

Jean_Ferro_1-1718642288705.png

 

Jean_Ferro_0-1718642260922.png

Still dosent work.

Only works on this way:

Jean_Ferro_2-1718642388148.png

 

@Jean_Ferro Yep, that's what I was referring to. Interesting, let me do some research as maybe there is some kind of formula firewall thing going on here.



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...

I tried this way too and it still doesn't work.

Jean_Ferro_0-1718644137339.png

I really appreciate your attention and help, I will continue working in the way it is working, if you have any more ideas I would be very happy if you shared them!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.