Forum Discussion
Filter based on a condition
- 4 years ago
I have just found out that writing the code with the whole CALCULATE inside de IF statement it works. Like this:
mymeasure = IF (1=1,
CALCULATE(
SUM(),
FILTER()
),
result if false
)
But if someone has a more elegant way to accomplish what I have explained in the first post I would really like to learn.
Best regards,
Isoka
Dear amitchandak , thank you for your interest!
Let me bring this closer to the reality, I apologize for being to generic.
I used a table like the one below and put column "Country" in a slicer.
Table _SegGeral2:
| Country | In_Out1 | In_Out2 | In_Out3 | In_Out4 |
| Brazil | ||||
| Germany | 10 | 23 | 9 | 35 |
| USA | 60 | 62 | ||
| Colombia | ||||
| Denmark | 32 | 46 | 50 |
Then I created the following measure to sum values on table "QUOTE_REPORT" :
| Value | In_Out | Cond2 | Cond3 |
| 30 | 10 | x | g |
| 65 | 80 | y | d |
| 796 | 63 | s | r |
| 34 | 46 | d | t |
| 214 | 50 | q | t |
| 375 | 103 | e | t |
| 29 | 10 | f | y |
| 785 | 50 | s | g |
| 992 | 92 | s | n |
In the fact table there will always be a value in column "In_Out" but in table "_SegGeral2" column "In_Out1" there may be blank values.
The expected result is that when I select Brazil in the slicer, since there is no value in column "In_Out1", the filter will not be included in the SUM statement. But when I select Germany it must be included.
I will have the same situation for "Cond2", "Cond3" and a few other conditions. That is why I am trying to find a way to include a filter, inside a SUM statement, conditioned to the existence of values in certain columns on the dimension table.
Hope I was able to make it clearer.
Best regards,
I have just found out that writing the code with the whole CALCULATE inside de IF statement it works. Like this:
mymeasure = IF (1=1,
CALCULATE(
SUM(),
FILTER()
),
result if false
)
But if someone has a more elegant way to accomplish what I have explained in the first post I would really like to learn.
Best regards,
Isoka
- Anonymous4 years agoNot applicable
Hi Isoka ,
Thank you for sharing, is there anything else you need help with regarding this thread? If not, would it be possible to mark your reply as Answered? This will also help the others in the community who have similar problems to yours to find a solution as soon as possible. Thank you.
By the way, about Table _SegGeral2, maybe you can select all in_out columns and unpivot them in Query Editor first as in the figure below, so that it may be more convenient to calculate later.
Best Regards