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

Top Solution Authors