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
netanel
Post Prodigy
Post Prodigy

Replace SELECTEDVALUE to something else

Hi All!

 

i have this Dax:

Gross USD =
IF (
SELECTEDVALUE( 'db 2021'[Source]) = "Amazon",
CALCULATE (
DIVIDE (
( SUM ( 'DB 2021'[Gross USD] ) + SUM ( 'DB 2021'[Fee USD] ) ),
COUNTROWS ( 'Date' )
),
KEEPFILTERS ( 'Date'[Date] < TODAY () )
),
CALCULATE (
DIVIDE ( SUM ( 'DB 2021'[Gross USD] ), COUNTROWS ( 'Date' ) ),
KEEPFILTERS ( 'Date'[Date] < TODAY () )))
 

My problem is, the formula only works when i filter Amazon
I want it to work whenever source = Amazon

Just need to replace SELECTEDVALUE right?

Source condition.JPG

 

Please Help

 







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

Connect on Linkedin
linkedin.com/in/netanel-shriki
1 ACCEPTED SOLUTION

Like Samarth said you should get the column as a suggestion. Are you using a measure now? If so you here is a completely new approach to this:

CALCULATE (
DIVIDE (
( SUM ( 'DB 2021'[Gross USD] ) + SUM ( 'DB 2021'[Fee USD] ) ),
COUNTROWS ( 'Date' )
),
KEEPFILTERS ( 'Date'[Date] < TODAY () ),filter('db 2021','db 2021'[Source] = "Amazon"))
+


CALCULATE (
DIVIDE ( SUM ( 'DB 2021'[Gross USD] ), COUNTROWS ( 'Date' ) ),
KEEPFILTERS ( 'Date'[Date] < TODAY () ),filter('db 2021','db 2021'[Source] <> "Amazon"))
 
The logic here is to use one calculate logic when customer is Amazon (include the fee there) and other when it is not.




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

Proud to be a Super User!




View solution in original post

13 REPLIES 13
ValtteriN
Super User
Super User

Hi again 😁,

When using selectedvalue in a measure like in your example the logic is applied in the filter context. E.g. here only customer A's Dates are shown as blank:
(edit: I forgot to add my example. Here the source column -> in this case customer, is not acting as a filter. @netanel 😞

ValtteriN_0-1641828495678.png

 



If you want to remove the filter context you can use functions like ALL or REMOVEFILTERS. Based on your example the measure should work? What am I missing here?

Edit 2:

Here is an example on how to do this kind of logic in a column:

IFColumn = IF('Matrix example'[Brand]="Wood",'Matrix example'[Value],'Matrix example'[Value]+'Matrix example'[Value2])
ValtteriN_1-1641828789197.png

 





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

Proud to be a Super User!




@netanel 

So now that I know it is a column a simple IF logic should be fine. As you can see in my example above, if you are creating a calculated column there is no need for MAX/SELECTEDVALUE. e.g.

IF (
'db 2021'[Source] = "Amazon",
CALCULATE (
DIVIDE (
SUM ( 'DB 2021'[Gross USD] ) + SUM ( 'DB 2021'[Fee USD] ) ),
COUNTROWS ( 'Date' )
),
KEEPFILTERS ( 'Date'[Date] < TODAY () )
),
CALCULATE (
DIVIDE ( SUM ( 'DB 2021'[Gross USD] ), COUNTROWS ( 'Date' ) ),
KEEPFILTERS ( 'Date'[Date] < TODAY () )))







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

Proud to be a Super User!




Hi @ValtteriN 

Source condition 1.JPG

 

 

 

 

 

Thanks I think it's really close ...








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

Connect on Linkedin
linkedin.com/in/netanel-shriki

@netanel just remove source from this line 'db 2021'[Source] = "Amazon", and click on ctrl+space bar it will suggest column names then select source column from there. It will work.

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18 

 

It only offers me formula...

And I do not understand why








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

Connect on Linkedin
linkedin.com/in/netanel-shriki

Like Samarth said you should get the column as a suggestion. Are you using a measure now? If so you here is a completely new approach to this:

CALCULATE (
DIVIDE (
( SUM ( 'DB 2021'[Gross USD] ) + SUM ( 'DB 2021'[Fee USD] ) ),
COUNTROWS ( 'Date' )
),
KEEPFILTERS ( 'Date'[Date] < TODAY () ),filter('db 2021','db 2021'[Source] = "Amazon"))
+


CALCULATE (
DIVIDE ( SUM ( 'DB 2021'[Gross USD] ), COUNTROWS ( 'Date' ) ),
KEEPFILTERS ( 'Date'[Date] < TODAY () ),filter('db 2021','db 2021'[Source] <> "Amazon"))
 
The logic here is to use one calculate logic when customer is Amazon (include the fee there) and other when it is not.




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

Proud to be a Super User!




@ValtteriN 

Thank you!
It works great
Thanks for the time i really appreciate it!

😊








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

Connect on Linkedin
linkedin.com/in/netanel-shriki

Hi again 😉 @ValtteriN 

You're right,
But I do not use a source column as a filter

I just want that every time that Source = to Amazon
Then connect the Fee column to the Gross column

 








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

Connect on Linkedin
linkedin.com/in/netanel-shriki
Samarth_18
Community Champion
Community Champion

Hi @netanel ,

 

You can try below code:-

Gross USD =
IF (
MAX( 'db 2021'[Source]) = "Amazon",
CALCULATE (
DIVIDE (
( SUM ( 'DB 2021'[Gross USD] ) + SUM ( 'DB 2021'[Fee USD] ) ),
COUNTROWS ( 'Date' )
),
KEEPFILTERS ( 'Date'[Date] < TODAY () )
),
CALCULATE (
DIVIDE ( SUM ( 'DB 2021'[Gross USD] ), COUNTROWS ( 'Date' ) ),
KEEPFILTERS ( 'Date'[Date] < TODAY () )))

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

HI @Samarth_18 

 

MAX Brings me the same results...

 

 








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

Connect on Linkedin
linkedin.com/in/netanel-shriki

Just to clarify is the DAX you use a measure or a column?





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

Proud to be a Super User!




Hi @ValtteriN @Samarth_18 

 

Sorry friends,
I was thinking in the wrong direction and a bit complicated it.
I went backwards and the direction of @ValtteriN  is the right direction
The Gross formula works well so I'll just add the Fee to it whit +
The problem is I only need the Fee when the Source is "Amazon"
So that's what I've put together
The second formula gets Blank
Why?

 

1. 

Gross USD  =
CALCULATE(
DIVIDE( SUM( 'DB 2021'[Gross USD] ), COUNTROWS( 'Date' ) ),
keepfilters( 'Date'[Date] < TODAY())
 
2. Measure @ValtteriN 
Amazone Fee = IF (SELECTEDVALUE('DB 2021'[Source]) <> "Amazon", BLANK (), SELECTEDVALUE('DB 2021'[Fee]))
 
If I connect the two formulas I get nothing
Because the second formula brings me Blank







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

Connect on Linkedin
linkedin.com/in/netanel-shriki

Hi @ValtteriN 

a Column

Thanks for your time!

 








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

Connect on Linkedin
linkedin.com/in/netanel-shriki

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