Custom Column - IF Then Statement in Power BI - powerbi

I want to add a custom column in Power BI to return a value based on another column. In Excel I would write the formula as IF(D2="DR",C2,-C2).
In Power BI I tried writing the following IF([DR/CR]="DR" THEN [Amount] ELSE [Amount]*-1) this doesn't work so I then tried if([DR/CR]="DR",[Amount],-[amount])) when I wrote this it accepted it but I received the following error "Expression.Error: The name 'IF'; wasn't recognized. Make sure it's spelled correctly.
Basically the amounts shown in the "AMOUNT" column are all debit values and the DR/CR column indicates if it is a debit or credit. I would like to figure out a way to show the amounts as debit and credits so I can complete calculations. Thank you in advance.

Related

How to consolidate the sales data using DAX

Hi everyone,
I have a data table named as sales in PBI as shown in the screenshot above. I want to create a matrix visualizer to consolidate all the sales by month. The expected output for the matrix will be something like this:
I'm having challenge to use DAX formula to consolidate the sales. Right now, I'm using SUM(sales[Sales]) to calculate, but what I got in the matrix for each rows is the total sales. I tried to used SUMX as well but it doesn't work either. Any help or advise will be greatly appreciated!
If you have it stored as a string SUM functions won't work - which is the only error I can think of with data as simple as that.
You also don't need to make a function for something like this. Just make a new table with "Month & Year" and "Sales" it'll default to using SUM of sales if it's stored as a number or integer.

How to add a subtotal row to existing data in power bi

Can anyone help me add a subtotal row to existing data in power bi. Please see the sample output on the above snip.
If you're looking to add a subtotal to your matrix visualization in the report itself, you should use the paintbrush or customization icon on the frontend instead. There you're able to toggle subtotals and grand totals for both rows and columns. However, if it's important to have your backend data display the subtotal row, you can use M code in Power Query to "groupby" a column and summarize your data. See these links for sample code that have different techniques:
https://social.technet.microsoft.com/Forums/en-US/1891afde-7392-4d27-b920-dfd579837dc8/how-to-add-subtotal-in-a-row-in-power-query?forum=powerquery
https://community.powerbi.com/t5/Power-Query/Calculate-Subtotals-based-on-column-value-in-Power-Query-M/td-p/791788

Power Bi DAX - sum with filters

I am a Power Bi beginner, trying to solve the following issue.
I have got the following table:
enter image description here
I would like to get this result :
enter image description here
Basically the new measure should show sums for each project forecast.
Any help will be appreciated.
To get the final table you have to choose Table on Visualizations and organize columns in this way (see the screenshot). Then right click on Forecast in Values and check Don't summarize.
If it doesn't help, please check the data types.

How to show each date in a column just once (like Tableau does)?

I have the following table in Power BI Desktop table visualization:
I don't like that the same dates are repeated over many rows, and would like to show each day just once. Here's what I mean, this is made with Tableau:
How can I do this in Power BI? Thanks!
I found the answer here: how to group the values in power bi?. It's not as pretty, but it works.
In short:
1: changed the visualization from Table to Matrix
2: moved both the date and the middle column to the "Rows" field of the Matrix

POWER BI - GROUPBY() and SUMX()

Hello everyone I can't get why my measure or column (tried with both) doesn't work. I am beginner in Power BI (Advanced in TIBCO spotfire)
Mesure 1 = GROUPBY(VUE_TACHES;VUE_TACHES[PREF];VUE_TACHES[ACTIVITE];"group_by_gsp_activite";SUMX(CURRENTGROUP();VUE_TACHES[REEST]))
It's telling me that multiples colonnes can't be change in scalar value. Does someone have a clue? I looked on the internet and tried different formula but i couldn't do it.
I believe the answer is that you need to create a new table, instead of trying to add a column or measure.
Try this. Click on the "Modeling" tab and then on "New Table".
Then enter your code in the formula bar:
Table = GROUPBY(VUE_TACHES,VUE_TACHES[PREF],VUE_TACHES[ACTIVITE],"group_by_gsp_activite",SUMX(CURRENTGROUP(),VUE_TACHES[REEST]))
You should see this result: