Forum Discussion
Calculated column does not work?
Hi C4YNelis,
>>Finally (and this is where things go wrong), I want to fill the calculated column.
Where did you create the calculated column? In your scenario, there are several tables. From the screenshot, I am not reproduce the same scenario.
Based on my understanding, I try to create sample data shown in the screenshot below and test it as follows.
First I create a slicer including the Bom scenario’s field. Create a measure like yours, create a card used to display the result.
gefilterd scenario = If(CountRows(Test4)=1,VALUES(Test4[Bom scenario's]),Blank())
Finally, create a calculated using the following formula and get the desired result.
result = IF(Test4[Bom scenario's]="Order>90dgn",TRUE(),FALSE())
In addition, if you have multiple values in the field used in slicer like the first screenshot. Then it will return blank even though I use the same measure. Because the CountRows(Table13) is not 1. So it return the wrong result.
gefilterd scenario111 = If(CountRows(Table13)=1,VALUES(Table13[Bom scenario's]),Blank())
If this is not what you want, could you please post the .PBIX for better analysis?
Best Regards,
Angelia
- C4YNelis9 years agoAdvocate III
Hi Angelia,
first of all, thank you for your reply and my best wishes for 2017!
Forgive me my late reply, I had a couple of days off for the holiday.
I have multiple tables indeed, but I really only have one primary table (let's call this my "source" table). This table needs to be filtered selectively based on the chosen scenario (that's what I use the matrix for together with the calculated column (true/false) as input for a visuals filter.
Besides this source table, I have created a second table consisting of only one column, used to fill the necessary slicer. I'll call this the "helper" table.
The calculated column needs to be placed in the source table. In your example you created the calculated column in the helper table, however, that is no use unfortunately in my scenario.
You're right to say that it will not work when I would select more than one option in the slicer, however, in my report that would make no sense to begin with. This is specifically a report designed to filter out a specific workload based on the selected criteria.
Unfortunately I cannot just share the .PBIX due to the sensitive nature of the data. However, if I need to clarify anything, please ask.
I hope this clarifies the problem a bit?
Thanks again and best regards,
Niels
- C4YNelis9 years agoAdvocate III
I may not be able to post the original .pbix file, but I have created a new fictive .pbix file that generates the same problem. Please find it on dropbox as I cannot upload it here: Sample PBIX file
What I have done in this file to further downdrill to the actual problem (I hope):
I've created the same type of measure as before, reading a single value from the slicer:
Selected_Slicervalue = if(CountRows('Slicer_Criteria')=1;Values(Slicer_Criteria[Criterium]);Blank())To verify, I have a card to show the value.
I then tried creating multiple calculated columns to see how Power BI reacts:
1. First I have created the calculated column as I would ideally like to use it (eventually):
Row_Selected_1st_Attempt = If([Selected_Slicervalue]="18+"||[Selected_Slicervalue]="18-";if([Selected_Slicervalue]=Source_Table[Age];True;False);If([Selected_Slicervalue]="Male"||[Selected_Slicervalue]="Female";if([Selected_Slicervalue]=Source_Table[Sex];True;False);False))
This obviously did not work, the calculated column is completely filled with the value False. The printscreen below shows this (please note that the columns are not shown entirely in the same order due to an extra column I added afterwards).
2. Next I tried just to match one value (specifically testing with "18+"), keep things simple, right? As expected, this didn't work either.
Row_Selected_2nd_Attempt = If([Selected_Slicervalue]=Source_Table[Age];True;False)
3. I then thought I'd try a general logical test using an additional measure, testing for "18+" to be true or false and fill the column based on this measure being true, eliminating the possibility that this would result in false, rather than true. Again, not the desired result.
The measure (which evaluates to True, when selecting "18+", as can be seen from the card I added to the report):
Selected_is_True = [Selected_Slicervalue]="18+"
The column:
Row_Selected_3rd_Attempt = If([Selected_is_True]=TRUE();True;False)
Also, I don't understand why sometimes it persists in adding brackets when typing True and sometimes it just doesn't seem to care. The effect seems the same though.
4. Then I thought, let's see how the column behaves when I simply test for this exact value (basically, the same as how I used the measure).
Row_Selected_4th_Attempt = If([Selected_Slicervalue]="18+";True();FALSE())
Still, the whole column remains false, while I would expect it to be true.
5. Not giving up, I tried a different way of just forcing it to be true (there has to be some way?):
Row_Selected_5th_Attempt = If([Selected_Slicervalue]=[Selected_Slicervalue];True;False)
Now, slightly to my surprise, this time it did evaluate to true, however, the results naturally are useless this way.
6. And finally, what I also wanted to test, is whether I didn't make any mistake in my assumption that I could calculate the column based on the value in the column: "Age". Though I already knew this would work, I just wanted to be thorough.
Row_Selected_6th_Attempt = If(Source_Table[Age]="18+";True;False)
Now, here are the columns as they evaluated:
The results. Note that the columns are not entirely in order
I forgot to mention that again all calculated columns and measures are calculated in the Source_Table, which differs from the table with the Slicer_Criteria.
From what I've seen, my best guess is that it is simply not possible to use this value in a calculation because of the unrelated tables, however, I am relatively new to Power BI and I cannot really think of a reason why this would be so.
Hopefully someone does? Alternatively, if anyone knows of a different way of filtering the situation as desired..., I'm keeping all options open at this point.
Thank you again.
Best regards,
Niels
- C4YNelis9 years agoAdvocate III
Unfortunately I have still not managed to solve this problem. I can only conclude that it is simply not possible to create a calculated column based on a measure that (partly) uses an unrelated column from a different table. I don't really understand why this would pose an issue though, however, I have done a couple of simular tests and they all show the same results.
I have been able to solve my immediate problem via an alternative route, creating a dynamic solution via M Query, reading and splitting a column to their unique values mapped to their occurences, both individual and combined, with two different functions and an iterative loop.
If anyone is interested in the final solution, just let me know and I'll try to explain.
cheers,
Niels