How to add same measure used in different vizualiztions. power Bi? - powerbi

I have a measure [expense]. I have two filters filter1(current year expense) and filter2(prev year expense)
I have created two table in a Power Bi report, and used the same measure expense in them both of them such that,
The first table ignores filter 2(prev year expense) and only filter1(current year expense) is applied
The second table ignores filter1 and only filter 2 accepts.
Basically I want to have Current year and prev year expense in two separate tables. This I am able to achieve quite easily, using edit interactions.
But the problem is I also need a third table which should give the result as the total of the two tables. Since I am using the same measure in both the tables, how can I achieve this.
Note:: My total table total summation should change based on filters selected .
Basically table3=table1+table2.

Try something like this. Filter the third table with filter1(current year expense). I do not see better solution within your report logic.
CALCULATE(
[expense]
,tbl[Year] In {SELECTEDVALUE(tbl[Year]),SELECTEDVALUE(tbl[Year])-1}
)

Related

Using IN operator in DAX with Power Bi Desktop chart?

I'm new to DAX so please bear with me.
Can I use the IN operator in DAX to create a query directly in Power Bi desktop?
For example, the screenshot below displays over 120 curencies in DimCurrency.CurrencyName. Is it possible to create a DAX query where I can include all my filters using IN operator?
For example, maybe something like this?
CALCULATE (
[Sales Amount],
Products[Color] IN { "Red", "Black" }
)
The reason I'm interested in using DAX is because my current filter has over 200 different items, so I don't want to scroll through the 200-item list and select 5 different items.
This is a data modeling problem. In Dimensional Modeling terms your Dimension needs some additional attribute hierarchies to drive the filtering. This is just like why a Calendar table doen't just have a Day column, it needs Month, Year, Quarter, so you don't have to select all the individual Days.
Basically DimCurrency needs an additional column, so that you can include those 50 currencies by selecting fewer values of that new column.
One way to modify your data model is with DAX calculated columns, with an expression of the form
IsFacoriteCurrency = 'DimCurrency'[CurrencyName] in {"Algerian Dinar","Argentine Peso"}
you can also modify the data model in the data source or in Power Query.

Getting date for calculation

I am a new user of Power BI and I was wondering if it is possible to calculate the date difference that is present in two different tables but they both are connected to the third table in which I want to create a measure or a column using dax to calculate date difference:
The columns marked in red are dates and I want their difference to be calculated in the assumption table. I used the month number to build the relationship between these tables.
You can use a Measure as below-
date_diff =
DATEDIFF(
RELATED(d_nl[notification]),
RELATED(d_fc[file_closure_date]),
DAY
)
To know about other Intervals rather than DAY, you can visit Here.

Based on slicer selection create dynamic calculated table in Power BI

I’m new to Power BI. Currently facing similar issue explained below in my product development.
I have created power bi modle with below dimensions and facts from adventureworksDW.
Then I created a calculated table, which gives result as sum of sales group by ProductSubCategory and ProductCategory. Below is the DAX for the calculated table.
Now I want to create a new calculated table, which gives me TOPn ProductSubCategory based on the Total sales amount.
Below is the DAX to do this.
and model relationships looks like below.
I want this TOPn rows to be displayed based on filter condition on product category. Something like below.
This works fine when I hardcode the product category value in the DAX itself. But if I want to change this product category values from the slicer selection, then I didn’t get any results.
What you are asking for is not possible as Power BI is currently designed. Slicers cannot affect calculated tables. Calculated columns and calculated tables are evaluated once when the data is first loaded and are static until the data is refreshed.
However, you can get the table visual you want in a much simpler manner by writing the appropriate measure and putting that in the table instead of defining an entirely separate table.
TotalSales = SUM(FactInternetSales[SalesAmount])
The Top N filtering is available in the visual level filters settings.
You can simply use the SELECTEDVALUE function as shown below.
var __SelectedValue = SELECTEDVALUE('ProductSales'[EnglishProductCatogaryName])
return
Filter(
'ProductSales',
'ProductSales'[EnglishProductCatogaryName] = __SelectedValue
)
)

Is it possible to use a slicer as a parameter to a DAX Summarize function?

I have a FactLosses Table, and a DimAccumulation table. I have brought them into PowerBi and I have placed a slicer to choose which accumulation zones i am interested in.
Once the user has selected the zones, i want to perform a group by year on the losses and sum the losses into year buckets. But only on the data that applies to the zones the user picked.
I am using the following DAX code to do the group by like so...
Table = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))
The problem is the new table always produces the same result. i.e When i make changes to which accumulation perils should be included it makes no difference to the summation. (it is summing the entire table)
I'd like to use the slicer to filter the fact table and then have the DAX query run on the filtered list. Is this possible?
If you want these tables to be responsive to filters or slicers on your report, then you can't write these as calculated tables that show up under the Data tab since those are computed before any filtering happens.
To get what you want, you have to do everything inside of a measure, since those are what respond to slicers. If you're looking for the max loss year once the grouping and summing are completed, you can write a measure along these lines:
Year Max =
VAR CalculatedTable = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))
RETURN MAXX(CalculatedTable, [Losses By Year])
Writing it this way will allow the calculated table to respond to your slicers and filters.

Possibility for a measure to ignore slicers in powerBI without editing interactions

As the title says, is it possible for a measures values not to change by any means? It's not possible for me to edit interactions with the slicer as the graph contains other measures.
F.eks. If I have a Slicer with dates December, January and February, and I select January the measure should still show data for all 3 months.
I'm hoping there's some DAX function which allows this.
Yes, you can set the filter context within a measure.
For example, if you had a calculation that summed revenue,
= SUM(Sales[Revenue])
Then you could modify it to look something more like this:
= CALCULATE(SUM(Sales[Revenue]), ALL(Sales[Date]))
This would clear the slicer's filter and return the sum over all dates.