Power BI DAX calculated column to find alternatives from a different table - powerbi

I have the following datasets:
"Compare Data" table:
"Full Data" table
I'm looking to create a calculated column where I can later show and count who and how many alternative vendors to A and their Average Costs if "Model" and "Group" columns are used as slicers.
Ex:
If W5 is chosen from the "Model" slicer AND/OR EEC is selected from the "Group" slicer,
• Alternatives to A = B & E & R [Ignore A in the results]
• Number of Alternatives = 3
• Average Cost:
A = (100 + 150 + 105 +3000 +1215)/5 = 914
B = 85/1 = 85
E = 1115/1 = 1115
R = 450/1 = 450
I don't know if it should be a calculated column or a measure because I'd like to put these information in a Bubble Chart later where it shows A's Average Cost and its alternatives' costs with regard to "Model" and "Group" slicers.
Please if you have any solutions, can you show me how to get this done? Thank you so much!

Related

How do I create a quarter-over-quarter variance column or measure with a table of account balance totals by quarter?

I have a table that lists quarter-end account balances by account and business group and I'd like to create a measure or column that shows the quarter-over-quarter balance change for each company/account combo (e.g., Group A, Account 10000 quarter-over-quarter change is $500).
I've tried various formulas using the calculate function, but these don't work if I don't apply aggregation (SUM and SUMX are what I've tried) to the AMOUNT column. The aggregations seem to mess up the results. I either get blank values or duplicate amount values. I think it's because the amounts don't need to be aggregated. They're already aggregated values.
How can I do a simple subtraction based on quarterly dates without having to aggregate my amount column?
The formula(and similar variations) I've tried:
QtrChange =
VAR CurrentAmt = TABLE1[AMOUNT]
VAR PrevAmt = CALCULATE(SUM(TABLE1[AMOUNT]), PREVIOUSQUARTER(TABLE1[DATE].[DATE])
RETURN = CurrentAmt - PrevAmt
Table example:
Business Group
Account
Quarter end balance
Quarter
A
100000
$2000
3/31/22
A
200000
$3000
3/31/22
B
100000
$4000
3/31/22
B
200000
$5000
3/31/22
Edit:
Edited DAX formula with labels tying to example table, for better clarity:
QtrChange =
VAR CurrentAmt = TABLE1[Quarter end balance]
VAR PrevAmt = CALCULATE(SUM(TABLE1[Quarter end balance]), PREVIOUSQUARTER(TABLE1[Quarter].[DATE])
RETURN = CurrentAmt - PrevAmt

PowerBI DAX Query - undo filter slicer on certain values based on expression

I have below table structure:
enter image description here
here I want to put a date slicer in Power BI to filter on dates and return the count of total rows as total in the card as shown below:
enter image description here
simple, the only twist is that I want to have the total of hybrid car added at all times.
i.e.
Brands before 5/25/2020 = 4 Hybrid + 1 Electric = 5
Brands before 12/5/2020 = 4 Hybrid + 3 Electric = 7
I have found a solution, which is creating a view in my database, which jus holds the number count of hybrid car (select count(*) from table where cartype = 'hybrid') and using it to sum with filter rows in power bi - but I am looking for a solution completely in Power BI DAX query.
any measure I have tried to create in power bi is filtered by date slicer and so doesn't work.
Create these measure:
TOTALROWS = COUNT('cars'[brand])
ELECTRIC_NUM = CALCULATE([TotalRows],('cars'),'cars'[cartype]="ELECTRIC")
HYBRID_NUM = CALCULATE([TOTALROWS],ALL('cars'),'cars'[cartype]="HYBRID")
TOTALBYBUSINESSLOGIC = CALCULATE([ELECTRIC_NUM]+[HYBRID_NUM])
Now use the last measure (i.e. TOTALBYBUSINESSLOGIC) to be used in your Card to display the total, Notice the expression diffrence between ELECTRIC_NUM and HYBRID_NUM
(In HYBRID_NUM I have used ALL, All will have it bypass the Date Slicer filter) whereas ELECTRIC_NUM will only proivde sum of rows falling in the active date sliver range.

PowerBI: Get values from a column based on a measure filter

I have a PowerBI dashboard that contains casino guest information, including their latitude and longitude coordinates. The dashboard allows a user to input a zip code and select a radius around that zip (slicers). When doing so, it filters the table of casino guests to only those with a distance (measure) less than or equal to the radius chosen. I used this distance measure and logic to create another measure "InRadius" that would show 1 or 0 depending on if the given guest is within the radius. then used this "InRadius" measure as a filter for my table, as well as other visuals. everything works fine, except I am wanting to add a "between" slicer that will filter guest's ADW Range and I am unable to filter this slicer by my measure "InRadius", therefore my min and max values for ADW in the slicer, do not accurately reflect the ADW ranges for guests filtered in my table. Is there any way for me to get around this? Is it possible to create a new measure that I could use specifically for this slicer? Is it possible to filter a slicer by only the values present in an already filtered table? In general, I am just wanting to create a slicer that filters a columns values based on a measure's value, but can't figure out how to go about accomplishing it.
some codes I have tried while creating a new measure but haven't given desired result:
InRadiusADWFilter = IF([InRadiusPatron]=1, VALUES(TF_MapRadius[ADWNet]))
InRadiusADWFilter = FILTER(VALUES(TF_MapRadius[ADWNet]), [InRadiusPatron]=1)
InRadiusADWFilter = CALCULATE(VALUES(TF_MapRadius[ADWNet]), [InRadiusPatron]=1)
Here is my code for my measure distance:
// Haversine/great-circle distance calculation adapted from Stack Overflow: https://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula
VAR __latSelected = SELECTEDVALUE('TF_MapRadius'[maplat])
VAR __lonSelected = SELECTEDVALUE('TF_MapRadius'[maplong])
VAR __radius = 3956
VAR __multiplier = PI()/180
VAR __latDiff = (MIN('Selector'[Latitude])-__latSelected) * __multiplier
VAR __lonDiff = (MIN('Selector'[Longitude])-__lonSelected) * __multiplier
VAR __formula1 =
SIN(__latDiff/2) * SIN(__latDiff/2) +
COS(MIN('Selector'[Latitude]) * __multiplier) * COS(__latSelected * __multiplier) *
SIN(__lonDiff/2) * SIN(__lonDiff/2)
VAR __formula2 = 2 * ATAN(DIVIDE(SQRT(__formula1),SQRT(1-__formula1)))
VAR __distance = __radius * __formula2
RETURN __distance
here is my code for the measure "InRadius":
InRadiusPatron = if('TF_MapRadius'[Distance2] < Radius[Radius Value],1,0)
I've created dummy table that represents my filtered table:
ID
PatronName
ADWNet
Distance
InRadius
1
Smith, John
325,555
5.2
1
2
Jobs, Steve
200
7.0
1
3
Jeter, Derek
90,000
10.1
1
4
Jordan, Michael
-2,567
14.5
1
If you have measure that returning 1/0 (for example InRadius), then you can filter your visualization (select it and go to filter pane).

Calculate difference between column or subtraction of column in matrix report power BI

How to calculate difference between column in matrix table in power BI? Below is the example
Category cool warm Diff
Colors
Blue 70 30 40
Black 50 50 0
Pink 40 60 -20
Category has many categories I have filtered out with cool and warm. I have tried
diff= CALCULATE(SUM(Value),Category="Cool") - CALCULATE(SUM(Value),Category="warm")`
but it's not working i am getting the same values of cool and warm in diff column when i am placing diff measure in the value pane.
To add to this How to fix the duplicated columns in each of the subcategory.
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"
)
)

Percent of total from subgroups - Power BI

I am new to Power BI and got stuck with the following problem:
For research purposes, I have some data about the participation of students of acourse (the example chart you can see is filtered by students not visiting the course.
The first barchart shows how many students visited those course, the second chart should show those values in percent, calculated from the subtotal.
So the value in percent of Bachelor in SS 15 should be 23,305% (total bachelor students in SS15 was 2533: 595 / 2533 * 100)
I am not able to get this values correctly calculated.
Thanks for your help!
EDIT
The Data is structured as followed:
Hash Semester Status Stg (...)
xxx1 SS 15 A Diplom
xxx2 WS 16/17 A Master
xxx1 SS 15 N Diplom
xxx1 SS 17 A Bachelor
xxx2 SS 15 N Bachelor
... ... ... ...
The hash is the identifier for the Student.
The data contains around 55.000 rows and is imported as an unstructured Excel-list. The chart is filtered by status.
Until now I dont use custom measures but the build in measures via drag and drop.
I got the percentage values by selecting "show value as percent from column total".
First, create these following 3 measures-
1.
hash_total = COUNT(your_table_name[Hash])
2.
hash_semester_total =
var cur_sem = MAX(your_table_name[Semester])
RETURN
CALCULATE(
COUNT(your_table_name[Hash]),
FILTER(
ALL(your_table_name),
your_table_name[Semester] = cur_sem
)
)
3.
hash_percentage = [hash_total]/[hash_semester_total]
Change the Type of measure "hash_percentage" as %
Now configure your clustered column chart as below-
The output will be as below-