IF statement based on dropdown result in google sheet - if-statement

I'm working with google sheet and seeking some help.
Below is the situation and expected outcome.
- there is Income column, Payment column, Currency column, Balance column
Income and payment is where numbers are put
USD, JPY, THB, SGD in dropdown for currency
wrote below to detect which currency is selected
=IF(H7="THB",G7*, IF(H7="USD",G7*, IF(H7 = "JPY",G7)))
(above calculation is not done in any of the 4 columns mentioned above)
Balance column is using below calculation
=IF(AND(F7="",G7=""),"",I6+F7-G7)
1: Input number of income / payment
2: Currency selected
3: calculate the currency rate
4: reflect the result in THB and perform the existing calculation on balance column
Could anyone please teach me how to do this.
Essentially, I would like to use the result of calculation performed based of pulldown result to perform another calculation.
In other words, in php or any language, I want to assign the calculation result to a valuable then use that valuable in different argument.
Thanks !

I believe that in your balance column you could do what you want by joining the 2 formulas you have above or by using a helper column. The only thing I do not see in your formulas is the currency rates that you want to assign to each currency. Where are you getting the rates from?
So in a combined formula you would place the following formula:
=IF(H7="THB",I6+F7-G7, IF(H7="USD",(I6+F7-G7)*usdrate, IF(H7 = "JPY",(I6+F7-G7)*jpyrate)))
You just need to change usdrate and jpyrate with the actual exchange rates for those currencies.
Hope it helps.

Related

Getting measure to only show positive values in matrix Power BI

I'm new to DAX. Looking for your expertise. Looked all over the web but couldn't find a proper solution.
I have a matrix that shows several factories and it's inventories, the rows being factory and SKU. I've created a measure that's the difference between two other measures. The overall idea is: I have a inventory quantity and an orders volume. I defined a "balance" measure that's inventory - sales. That is, what is still left for sale.
Normally it works fine, but when I have a negative value in balance, things get messed up. The subtotal in the factory row sums all the numbers, including negatives, giving me a balance subtotal that is smaller than it's supposed to be. I can't count the negatives. So I've tried to solve this by defining the measure as
Balance = IF([Inventory]>[Sales],[Inventory] - [Sales],BLANK())
Now this works fine visually to display only the positive values in balance, but still sums up the negatives in the factory subtotal.
How can I make this measure to only show and sum up the positives?
I appreciate your help.
P.S.: the inventory and sales measures are basically SUM's of different tables for simplicity and understanding by my part
Matrix with measures. The columns are "Estoque" as inventory, "Embarque programado total" as sales and "Saldo Disp. Venda" as the balance
Create a measure with the below code.
Balance = CALCULATE(SUM([Inventory]) - SUM([Sales]), FILTER(Table1, [Inventory]>[Sales]))
As it turns out, I was able to find a solution through trial and error. I changed my measure to (FatoEstoque is the table that contains the inventory numbers):
Balance= CALCULATE([Inventory]-[Sales],FILTER(FatoEstoque,[Inventory]>[Sales]))
Although I'm not even sure why it works (lol), it works! So I'm not complaining. This measure only sums up the positive values, showing the correct subtotal as I needed.
Filtering the Inventory table to values where [Inventory]>[Sales] works, but adding another filter with the Sales table and the same condition don't.
Here is an image comparing the results. The new measure is called SaldVender2

Power BI: Return sum of numerical data for each counterparty and its several currencies between two dates and its variation

I need your help regarding Power BI because I'm quite new with it. I'm struggling to compute and show what I want.
I have imported my table from a database.
What I want is to compute the sum of the Nominal for each Counterparty and each Currency, BUT it needs to respect the condition: start date <= date in the date table & end date > date in the date table. At the end, I want to show the result just like the last image, a dynamic table.
Moreover, after computing the sum of the nominal, I need to compute the difference between two dates and the % variation of it.
On my side, I was able to get the sum I want but the problem is I created columns for each counterparty and currency like 'AZE EUR', 'AZE USD', in the Date table.
BY doing this, I can't create a pie chart that defines the % of EUR or USD owned by AZE and HUB counterparties. So no dynamic chart.
I hope I was clear enough. If not let me know :)
Thank you in advance for all your helps.
NB: if the image can't be seen, let me know.

Power BI DAX Cannot display correct monthly of last year's figures in a Matrix visual

I have a "strange" problem in visualizing the values of the "last" year (that is the most current year with data of a full year). In the example delivered it is 2019 which holds the bookings facts. The year should be derived by a related table (LetztesVollesJahrDim) that holds a min/max date and year value for each company/entity. The DateDim table holds all dates and is configured to be the Date dimension. 
The relations are shown in the graphic below.
I created a Report that should display different matrix tables with different values:
one, that shows the last full year's monthly values by Cost Center (which works correct)
one, that shows all years monthly values including an estimated value for the current year (2020) (which also works correct)
one, that could drill down to the details level of the Facts and display the figures per month (in columns) of the last full year (i.e. 2019) putting the Cost Center and other groups down the most detailed level into rows. This Matrix makes use of Calculated Measures created with Tabular Editor.
At this point I can here you say... try it without the Calculated measures and indeed I did that by simply displaying a Card that got a Visual Filter to DateDim[M]=7 to simulate the appliance of each matrix's column. Problem is the same: The Month filter of the Visual (or within the Calculated Measure) is ignored and the yearly sum is displayed (~48k) which is wrong.
As I am currently an Expert in SQL Server DBMS but not in the Architecture of Power BI's DAX Models I am not truely aware about the consequences when and why filters are removed, ignored, overwritten or added at which level of modeling.
Originally I tried to create a simple Calculated Measure that reflects the last full year of the company. That works, but its usage in the huge Matrix was impossible as it was calculating forever. That's why I created the simple table "LetztesVollesJahrDim" to hold a persisted value for each company.
The idea is simple: Create a Query that inner joins these tables and display the Sum for each month [M] like this:
Fact[Turnover] - Fact[CompanyKey] -> CompanyDim[CompanyKey] <-> LastFullYear[CompanyKey] - LastFullYear[MostCurrentYear] -> DateDim[Y] - DateDim[DateKey] -> Fact[StapleDateKey]
So, what is the Problem?
I tried a couple of DAX queries and all come up with a different wrong value.
Following three different approaches for a Calculated Measure "Sum LY":
1. 
Σ LY = CALCULATE(SUM(KontobuchungenFact[UmsatzNegiert]), DATESBETWEEN(DateDim[DateKey], DATE(2019, 1, 1), DATE(2019, 12,31)))
2. 
Σ LY = CALCULATE(SUM(KontobuchungenFact[UmsatzNegiert]), SAMEPERIODLASTYEAR(DateDim[DateKey]))
[
3. 
Σ LY = CALCULATE(SUM(KontobuchungenFact[UmsatzNegiert]), KEEPFILTERS(DateDim[M]), USERELATIONSHIP(DateDim[J], LetztesVollesJahrDim[AktuellstesJahr]), USERELATIONSHIP(DateDim[DateKey], KontobuchungenFact[StapelDateKey]))
 
Filters being applied on the page/visual:
CompanyKey
DateKey >= 2018-01-01 (page filter that limits the displayed rows in yearly matrix to the last 3 ys)
Some other irrelevant keys
Visual configuration:
Relations:
Values/Rows in the LetztesVollesJahrDim table:
Calculated Measures/Table in Tabular Editor showing the calculation of the "01 Jan" column of the first Matrix, which displays correct results:
Impression of the Report:
So in summary I need a clue/DAX formula that recognizes the Monthes in each column and ideally uses the relations to the last year table trespassing the year's filter through DateDim to the Facts.
It is funny, that the upper matrix works, but not the one on the bottom. It is not possible to use the calculated measures approach of the first matrix in the last matrix because the performance would drop to > minutes calculation. So I cannot use the same approach and need a fast one.
Anybody an idea? :-)

How to get multiple category lines with bar chart in Power Bi?

Sample Data.
CompanyA,2019-01-01,29000
CompanyA,2019-02-01,35000
CompanyA,2019-03-01,43000
CompanyA,2019-04-01,27000
CompanyA,2019-05-01,45000
CompanyA,2019-06-01,21000
CompanyA,2019-07-01,26000
CompanyA,2019-08-01,27285
CompanyA,2019-09-01,26035
CompanyA,2019-10-01,24785
Expected Output.
My Boss has asked me to show sale trend by companies and month. but he wants it to be shown like below.
X axis should have Month Names
Bar lines should tell overall sales amount by month.
multiple lines should represent company sales amount.
i have achived this output by replacing 2 charts on each other (hidden one background). 
First i have taken a CLUSTERED COLUMN CHART and place a Line chart on it with hidden background.
Sample File
But for me this is just an adhoc solution and One more problem is that both chart's y axis doesn't match.
seeking for a good solution on this. either another good chart to represent this kind of data or how to achive it any other way?
Thanks in advance.
You can create measures for individual company, if number of companies is not a big number, and then put them in "Line values" to achieve the same result as above.
So For ex, if you have 5 companies in the data then create 5 different measures like below
CompanyA = calculate(sum(sales), filter(tbl, [company] = "CompanyA"))
like the above ex create measures for other 4 companies also

How can I pass user input from a what-if parameter to be used in a calculation in a measure?

I'm new to Power BI so please bear with me, I've searched extensively for a solution but haven't been able to find quite the right thing.
I have a data set that contains (among other things) transactions with amounts and financial periods stored as whole numbers, and what I need to do is use those to arrive at YTD totals. So the user would select a period from 1-12 and then the YTD measure should calculate the totals for the selected period PLUS the previous periods (said another way, it should filter OUT the periods greater than the selected period).
I've tried to filter the totals for the appropriate periods by referencing the selected value of the parameter using "<=" but haven't been able to make that work:
ytd = CALCULATE(SUM(data_tbl[Calculated USD]),data_tbl[PERIOD NUMBER]<=current_period[current_period Value])
I'm probably approaching this the wrong way, but somehow I need to calculate YTD based on the user selecting the desired period. Thanks for any advice.