how to aggregate columns from multiple tables in power bi - powerbi

I have two tables here and I want to sum up measure 3 and measure 4.
both the measures are calculated once. I want to show sum against every country I have in the tables eg: Germany(0.31+0.18= 0.49)
model data
new result

Have your tried :
NewMeasure := SumX(Filter(Country, AND(Measure4 <> Blank(), Measure3 <> BLANK()) ), MEASURE 3 + MEASURE 4)
and then on PowerBi on the data view you select your measure and change the format to be with 2 decimal values.

Related

PowerBi Distinctcount not working properly with 3 measures

I am having an issue using the Distinctcount function in DAX. I have a table with a total of 1,154,493 rows. I have a measure created to count the number of distinct values in column 1. I have another measure created to count the number of distinct values in column 1 with filters. I have a 3rd and final measure created to count the number of distinct values of column 1 with different filters. The issue I am running into is the count of measure 2 + measure 3 should equal measure 1 however added together they are GREATER than the value of measure 1 which is just a grand total. How is this possible? Unfortunately I can't share the table but below is the code I am using for the two measures:
Measure1=distinctcount('Table1'[Column1])
Measure2=calculate(distinctcount('Table1'[Column1]),'Table1'[CTest] = 1,'Table1'[CTest2] = "07")
Measure3=calculate(distinctcount('Table1'[Column1]),'Table1'[CTest] = 2,'Table1'[CTest2] = "07")
I am at a loss. Thank you in advance!!
For troubleshooting you should identify values of Column1 with Measure2 and Measure3 > 0, those are being added twice.

Power BI - how to create measure based on conditions

I have a base table 'Orders' with a column OrderNo, this column is being used in a visual.
I have another table 'Operations' with columns: OrderNo, OperationNo, TimeTaken (this is just a numeric column). This table is related to base table with OrderNo. Please note that one OrderNo can have multiple OperationNo.
I want to add a column to my visual 'TimeRemaining', which takes all OperationNo (from Operations table) for an OrderNo and sums the TimeTaken column.
How can I achieve this?
Power bi groups the data in a visual automatically.
if they are linked you can make a calculated column in Orders
TimeRemaining =
SUM ( OperationNo[TimeTaken] )
if you want a it in the Operations specifically then:
TimeRemaining =
CALCULATE (
SUM ( Operations[TimeTaken] ),
ALLEXCEPT ( Operations, Operations[OrderNo] )
)
NOTE.
the first is for a calculated column in Orders table
the second one is for the Operations table.

Power BI DAX measure calculation

Step1:
I have created a calculated table containing Level, Location, L2code from level sales data. I need to create a report that will count rows based on the level1 group.
Note that there are more levels in the table. This is only an example of one of the levels.
How can I count the rows for each level1?
Step2:
I need to create all combinations of counts based on location and l2 code and count the numbers.
like in example 2 location and 8 distinct l2code so it should be 2*8 =16 total possible rows.
How can I achieve this using the DAX measure?
Source data file
Output report
first one is a simple measure as below-
DistinctRowCount = Count(your_table_name[Level1])
Second one is bit tricky and you can try this below measure-
CrossCount =
var distinct_location =
calculate(
distinctcount(your_table_name[Location]),
allexcept(
your_table_name,
your_table_name[Level1],
your_table_name[Location]
)
)
var distinct_l2code =
calculate(
distinctcount(your_table_name[l2code]),
allexcept(
your_table_name,
your_table_name[Level1],
your_table_name[Location],
your_table_name[l2code]
)
)
return distinct_location * distinct_l2code
Sample output-

How do I manipulate measure values based on 2 other dimension tables

Power BI newbie here and I'm trying to figure how to craft my DAX to manipulate my measure values based on certain criteria in the other two tables.
Currently I have 2 separate tables which are joined by a One to Many relationship and a separate Measures table. (Total Sales Price is computed as sum of Sales Price)
My aim is to create a new measure where Total Sales Price is multiplied by 1.5x when DIM_Product_Type[Product Category] = "High".
New Measure =
CALCULATE (
SUM ( FACT_PriceDetails[Sales Price] ),
FILTER ( DIM_Product_Type, DIM_Product_Type[Product Category] = "High" )
) * 1.5
However this returns no values in my visual and I'm trying to discern if its a matter of the table joins or the DAX expressions.
Thank you for your time!
Your measure seems good.
It will select only those products with a Product Category of "High" and multiply them by 1.5 to give you result. i.e. Give me the sum of all "High" Product category Price details multiplied by 1.5.
What you need to check is:
Product Serial Numbers match across the two tables
Your Product Category does indeed contain the category "High"
You have entries in FACT_PriceDetails that link to a DIM_Product_Type that has a category of "High"
Check you have not set any filters that could be hijacking your results (e.g. excluding the "High" product category product type or the realated fact/s)
Option-1
You can do some Transformation in Power Query Editor to create a new column new sales price with applying conditions as stated below-
First, Merge you Dim and Fact table and bring the Product Category value to your Fact table as below-
You have Product Category value in each row after expanding the Table after merge. Now create a custom column as shown below-
Finally, you can go to your report and create your Total Sales measure using the new column new sales price
Option-2
You can also archive the same using DAX as stated below-
First, create a Custom Column as below-
sales amount new =
if(
RELATED(dim_product_type[product category]) = "High",
fact_pricedetails[sales price] * 1.5,
fact_pricedetails[sales price]
)
Now create your Total Sales Amount measure as below-
total_sales_amount = SUM(fact_pricedetails[sales amount new])
For both above case, you will get the same output.

Power BI calculate the difference between two columns in a multi level matrix

Here is the source data:
Columns: [Version, Unit, Customer, Quarter, Sales)
Here are the potential values:
*Note: We may have 10 different versions and 20+ different quarter year combinations.
Here is the output matrix in Power BI:
*Users can select a Version and two quarters to compare.
Here are the Power BI Visualizations and Fields:
I would like to create a measure to calculate the difference between Version 1 and 2 like this (Columns E and H):
I'm able to create a new table with columns of sales for Version 1,2,3 then calculate the difference. The problem is I need the version and quarter to be dynamic. Any ideas how to do this in Power BI?
You can do something like
Delta = IF (HASONEVALUE('Table'[Version]),
SUM('Table'[Sales]),
CALCULATE(sum('Table'[Sales]), LASTNONBLANK('Table'[Version], sum('Table'[Sales])))
- CALCULATE(sum('Table'[Sales]), FIRSTNONBLANK('Table'[Version], sum('Table'[Sales])))
)
So whenever you have two versions in the filter context, it subtracts the first from the last, and whenever only one version is in the filter context, it passes the value through.
To add to this.
How to fix the duplicated columns in each of the subcategories.
I used the below DAX but somehow it's duplicated the calculated column "Delta TMCGP%" in all the subcategories. when i just want to show it at the end of the matrix table (Power BI)
Delta TMCGP% = CALCULATE([TMCGP%], FILTER( ALL(BC_Dashboard_V4_Standard[TYPE (groups)]), BC_Dashboard_V4_Standard[TYPE (groups)]="4_CWV") ) - CALCULATE([TMCGP%], FILTER( ALL(BC_Dashboard_V4_Standard[TYPE (groups)]), BC_Dashboard_V4_Standard[TYPE (groups)]="5_POR" ) )