Power BI- DAX measure-Table Condition based on the multiple if - if-statement

I have a 2 tables, Table 1 is "Data" and Table 2 is "Rule". How can I apply multiple if condition based on the table condition in Power BI?
Table-Data-(Column A, B and C is my Raw data)
Column A contain Text (Code)
Column B contain Number (Usage)
Column C contain Text (Usage Unit)
Column D output for usage column
Column E output for usage Unit column
Note: column D and E my output column based on the column A to C
enter image description here
Table 2- Rule-(This is my condition table for usage and usage unit according to the code
enter image description here
Column A contain the following code "MII", "KKR", "CHE" and "RCB" then usage column can not be blanks or 0 and usage unit column must be blanks for the code "MII" and the remaining codes usage unit can be blanks or the usage unit must be match the following two codes "DMK" or BJP".
Column A contain the following code "001", "KXP", "SRH","DEL" and "RRL" then usage column must be blanks and usage unit column must be blanks as well.
Example;
enter image description here
code Usage UsageUnit Usage(Output) Usage unit(Output)
001 0.00 Okay Okay
001 1.00 DMK Not okay Not okay
MII 0.00 BJP Not okay Not Okay
MII 1.00 OKAY OKAY
Additional condition for usage columns has 999 then usage output is "xx".
https://www.dropbox.com/s/cozopedtucklomu/CONDITION%20MATCH.xlsx?dl=0
https://www.dropbox.com/s/k68p2mru6yqob6z/CINDITION-MATCH.pbix?dl=0

You can use SWITCH in your CalculatedColumn/Measure. The first argument is TRUE(), second -> our condition evaluated to true, third output, forth, next condition, fifth, output and so on.
SWITCH (
TRUE(),
'DATA'[Code] in {"MII", "KKR", "CHE", "RCB"} && NOT(ISBLANK('DATA'[USAGE]), "ConditionOuptput",
'DATA'[Code] in {"001", "KXP", "SRH","DEL" ,"RRL"} && ISBLANK('DATA'[USAGE]), "SecondConditionOutput",
"Else goes here"
)

Related

I am tracking my investments - If column 2 (contains my contribution) is less than column 3 (investment return), return column 1 (date of occurrence)

I have a spreadsheet on Google Sheets that tracks my investment. Based on average returns I have calculated the average return rate over the years.
First column no.1 has a list of dates. Column no.2 has my contribution. Column no.3 has the average return.
I would like to do the following if statement: if(column2<column3)return(column1)
This is so I can see the date my returns become more than my contributions.
This code assumes that column1 is A, column2 is B and column3 is C.
the formula for the IF statement is:
first the thing you want to test
next the return value if true
last the return value if false.
I have set false to return 0, but you might want something else.
=IF($B1<$C1;$A1;0)

DAX selecting and displaying the max value of all selected records

Problem
I'm trying to calculate and display the maximum value of all selected rows alongside their actual values in a table in Power BI. When I try to do this with the measure MaxSelectedSales = MAXX(ALLSELECTED(FactSales), FactSales[Value]), the maximum value ends up being repeated, like this:
If I add additional dimensions to the output, even more rows appear.
What I want to see is just the selected rows in the fact table, without the blank values. (i.e., only four rows would be displayed for SaleId 1 through 4).
Does anyone know how I can achieve my goal with the data model shown below?
Details
I've configured the following model.
The DimMarket and DimSubMarket tables have two rows each, you can see their names above. The FactSales table looks like this:
SaleId
MarketId
SubMarketId
Value
IsCurrent
1
1
1
100
true
2
2
1
50
true
3
1
2
60
true
4
2
2
140
true
5
1
1
30
false
6
2
2
20
false
7
1
1
90
false
8
2
2
200
false
In the table output, I've filtered FactSales to only include rows where IsCurrent = true by setting a visual level filter.
Your max value (the measure) is a scalar value (a single value only). If you put a scalar value in a table with the other records, the value just get repeated. In general mixing scalar values and records (tables) does not really bring any benefit.
Measures like yours can be better displayed in a KPI or Multi KPI visual (normally with the year, that you get the max value per year).
If you just want to display the max value of selected rows (for example a filter in your table), use this measure:
Max Value = MAX(FactSales[Value])
This way all filter which are applied are considered in the measures calculation.
Here is a sample:
I've found a solution to my problem, but I'm slightly concerned with query performance. Although, on my current dataset, things seem to perform fairly well.
MaxSelectedSales =
MAXX(
FILTER(
SELECTCOLUMNS(
ALLSELECTED(FactSales),
"id", FactSales[SaleId],
"max", MAXX(ALLSELECTED(FactSales), FactSales[Value])
),
[id] = MAX(FactSales[SaleId])
),
[max]
)
If I understand this correctly, for every row in the output, this measure will calculate the maximum value across all selected FactSales rows, set it to a column named max and then filter the table so that only the current FactSales[SaleId] is selected. The performance hit comes from the fact that MAX needs to be executed for every row in the output and a full table scan would be done when that occurs.
Posted on behalf of the question asker

Can I make the values of an IF function into equations?

I'm working on a simple budget sheet in Google Sheets, and want to know if I can make the values of an IF function into an equation.
Column A describes the activity (as in, purchased DVD, received paycheck, etc).
Column B lists the amount of the activity if it was income; otherwise, it remains blank.
Column C lists the amount if the activity was an expense; otherwise, it remains blank.
Column D is my total amount, which takes the total amount in the cell directly above it and either adds to that value with the value in column B, or subtracts from that value with the value in column C. I have to personally input that equation, which is pretty time-consuming.
I was hoping to use column E to be a row that I mark as "Y" if that row was income. Otherwise, I would leave it blank.
Then I wanted to replace the equation in column D with an IF statement that checks if column E has a "Y" in it. If it does, then it performs the addition equation using columns D and B. (And if E is blank, then the equation simply has column C subtracted from column D.)
Say I have the following table:
1. Col. A || Col. B || Col. C || Col D.
1. Event || Income || Expense || Total
1. START VAL.||--------||---------|| $100.00 ||
2. Hamburger ||--------|| $10 || =D3-C4 ||
3. Paycheck || $20 ||---------|| =D4+B5 ||
Instead, I'm hoping to add column E so the table looks like this:
1. --Col. A---||-Col. B-||--Col. C-||----Col D.----||-Col. E----||
2. --Event----||Income--||-Expense-||----Total-----||-Is Income?||
3. STARTVAL. ||--------||---------||-----$100-----||-----------||
4. Hamburger ||--------|| $10 ||--*FORMULA 1*-||-----------||
5. Paycheck ||--$20---||---------||--*FORMULA 2*-||-----Y-----||
I thought that the FORMULA 1 would have to look like this:
=IF(E4="Y",(D3+B4),(D3-C4))
Formula 2 would look like this:
=IF(E5="Y",(D4+B5),(D4-C5))
You can see that having to update each cell by 1 depending on if it's income or an expense is inefficient...
I would expect column E to cause the IF function in column D to produce new equations depending on the value in column E, but all I get in Google Sheets is
Formula Parse error
try this formula in D4 cell and drag down:
=IF(E4="Y"; D3+B4; D3-C4)
if that works delete everything in range D4:D and paste this in D4 cell:
=ARRAYFORMULA(IF(LEN(A4:A); IF(E4:E="Y"; D3:D+B4:B; D3:D-C4:C); ))

sap hana calculated column check for multiple IDs

i want to create a calculated column, which will show two values: Y or N
2 columns are here important, "VAT-ID" and "CUSTOMER-ID". the calculated column will check if a customer-ID has multiple VAT-IDs. If yes the value "Y" should be displayed, else "N".
for example, the first 5 rows of the customer-id column are:
123456
654321
666666
123456
654321
the first 5 rows of the VAT-id column are:
EE999999999
AA999999999
GG999999999
KK999999999
AA999999999
the first 5 rows of the calculated column should be then:
Y
N
N
Y
N
any Help would be appreciated
Calculated columns don’t allow for aggregations across groups or other than the current row.
What you can do to achieve your goal is to create a separate aggregation node and count distinct VAT-IDs grouped by CUSTOMER-ID.
With this, you can now have a calculated column that checks for VAT-ID-COUNT > 1 and map it to your Y/N values.
As Lars mentioned it is not possible to use a window function within a calculated field on HANA table
But you can use following query to check if VAT number is multiple for a customer or not
select
CustomerId, VATID,
case
when (count(*) over (partition by CustomerId, VATID)) > 1
then 'Y'
else 'N'
end
from CustomerVAT;

Power BI - how to format Numeric value from One Column but show different format on Row level

I would like to ask how to format each row individually but those data comes from same column
for example
Col1 Measure
A 1.01
B 0.02
C 2.11111
so that when i have a table chart, it want it to show
Col1 Measure
A 1 (wholeNumber)
B 2% (Percentage)
C 2.11 (two decimals)
Thanks guys
You can only have one format associated with a column or measure.
If you have a measure that needs to return different formats, your only option is to convert them all to text type and specify how to display the format using FORMAT().
For example, a measure could look like this:
Measure = SWITCH(VALUES(Table1[Col1]),
"A", FORMAT(COUNTROWS(Table1), "0"),
"B", FORMAT(SUM(Table1[Value])/[TotalValue], "0%"),
"C", FORMAT(SUM(Table1[Value]), "Standard")
)
These should look OK in a table, but remember that they are text.