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
Bakhtawar
Post Patron
Post Patron

Varaibles in power bi measure

i tried this measure in power bi ..

Own_Damage_OS = VAR VpeDate = [VpeDate] return
CALCULATE (
    SUM ( OS_excel[OS_AMOUNT] ),Claims_excel[COVER_NAME]="Own Damaage",
   Premium_Excel[LOB] = "MOTOR",OS_excel[AS_OF_DATE]=VpeDate

)

BJMuY

 

but the problem is that when i called this "OS_excel[AS_OF_DATE]=VpeDate" this shows same figures in every date like this

but the actual result is this

FBXz4

is there any solution

3 REPLIES 3
Anonymous
Not applicable

First of all, you should never name your variables the same way you name measures. Second of all, I think it would be worth reading something on how DAX works and especially how filtering in CALCULATE works. Third of all, please always remember that the people who try to help you have no idea about what model you're working with. So, if you want to get answers to your questions, you should take care of exposing as much detail as possible. Maybe even send an example file with data (put the file on a shared drive like OneDrive or GoogleDrive and paste a link to it remembering to set the right permissions). If you don't get answers, then it probably means nobody is able to understand your problem. Try to be as clear as the sun. Good English will also help others understand what you're after.

 

Having said all that, I think you should try this (I don't have enough knowledge about your model to guarantee it'll do what you want in all circumstances):

 

Own_Damage_OS =
VAR __vpeDate = [VpeDate] -- What does this measure return?
RETURN
    CALCULATE (
    
        SUM ( OS_excel[OS_AMOUNT] ), -- This should be a measure on its own.
        
        Claims_excel[COVER_NAME] = "Own Damaage",
        Premium_Excel[LOB] = "MOTOR",
        
        KEEPFILTERS( OS_excel[AS_OF_DATE] = __vpeDate )
    )

Best

Darek

in this measure i set date like this "VpeDate = date(2017,12,31)" so when i drag this into sheet and user change date then according to date change data will be displayed .. i also attached sample Power bi file e.. kindly check

 

https://www.dropbox.com/s/94mj2uebvlmqqep/Claims1.pbix?dl=0

Anonymous
Not applicable

Well, if you set  "VpeDate = date(2017,12,31)", then no wonder that you get the same output for all the selections of dates. It can't be any different since the date you're filtering by is ALWAYS THE SAME.


What you need is a measure that will be aware of the selection in the date column, which changes on each row. So you should do something like:

 

-- Definition of the basic measure:
[Total OS Amount] = SUM ( OS_excel[OS_AMOUNT] )

-- Definition of the second measure you're after:
Own_Damage_OS =
VAR __onlyOneDateSelected = HASONEFILTER( OS_excel[AS_OF_DATE] )
var __result =
    CALCULATE (
        [Total OS Amount],
        Claims_excel[COVER_NAME] = "Own Damaage",
        Premium_Excel[LOB] = "MOTOR"
    )
return
	if( __onlyOneDateSelected, __result )

Best

Darek

 

Best

Darek

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.