RANKX in table and slicers - powerbi

This is table Fact:
Date Person Place Status Sales
01/01/2020 ABC North Active 9852
14/01/2020 DEF North Active 3452
17/01/2020 GHI North Active 9084
02/02/2020 GHI North Active 4902
14/02/2020 GHI North Active 4659
14/02/2020 DEF South Inactive 5000
23/02/2020 GHI North Active 1685
10/03/2020 GHI North Active 6401
21/03/2020 ABC Center Active 4742
09/04/2020 ABC Center Active 6325
14/04/2020 ABC Center Active 8329
27/04/2020 ABC Center Inactive 7740
28/04/2020 ABC Center Inactive 5091
02/05/2020 ABC Center Inactive 3763
04/05/2020 ABC Center Inactive 1434
06/05/2020 DEF Center Active 3718
22/05/2020 DEF South Active 6639
03/06/2020 DEF South Active 5672
12/06/2020 DEF South Active 5268
16/06/2020 DEF South Active 3358
I want to calculate the ranking of sales, depending on slicers for dimensions date, person, status and place.
So:
This measure:
TotalSales = SUM('Fact'[Sales])
Gives me the to total sales.
And:
This measure:
Ranking =
IF([TotalSales],
RANKX (
ALLSELECTED ('Fact'),
CALCULATE ( [TotalSales] ),
,
DESC,
DENSE
))
Is supposed to give me the ranking.
And it does, if all the dimensions are in:
However, if I remove the date:
This is non-sense. Can anyone help calculating the rank? Thanks

Sorry I'm replacing my answer completely because I misunderstood your problem.
I used the following:
Rank1 =
CALCULATE(
RANKX(
ALLSELECTED(Table1[Person], Table1[Place], Table1[Status]),
CALCULATE(
SUM(Table1[Sales])
)
)
)
Using your data, I made the visuals below, and am able to slice by place, person, and status. The problem with slicing by date, however, is that it's too granular, so that everything becomes #1 within that date period. You may want to add new columns like "Year" or "Quarter" which you can then add to the ALLSELECTED() statement in order to rank by, say, the person's best quarter, or the area's best year.

I opened your file & have some good news. I was able to find the issue.
STEP 1
Select all the Months & Places in your filters in the top. Hold CTRL to select multiple items. On the right, get rid of all the things that are in the way. Just check what I show here.
STEP2
Un-check the Date to see that the report goes crazy.
STEP 3
Un-check Total Sales & check Sales instead. You can also re-check Date here.
STEP 4
Hit the drop-down menu for Sales & select Don't Summarize.
STEP 5
Enjoy that you now have all 20 records again, but with no Date showing.

Related

How to filter a Card visual by a RANKX measure value in Power BI?

I'm creating a dashboard with a number of fictional sports teams, where teams can earn points every season. The image below shows the total standings table (of all seasons added together), with the Rank1 column next to it. The Rank1 column was created with this measure:
Rank1 =
CALCULATE(
RANKX(
ALLSELECTED(SeasonResults[Team]),
CALCULATE(
SUM(SeasonResults[TotaalPtn])
)
)
)
Table without selecting a specific season:
Now I want to highlight the number one team in a separate Card visual. So I would prefer to create a Card in which I filter by 'Rank is 1', with the 'First team name' displayed in the Card. However, this is not possible because I cannot put the rank measure as a filter a the Card.
The Card, just like the table, should adjust when a specific season is selected. For example, if I select Season 2, you can see that Sandborn was the frontrunner at the time. In that case, Liskeard should also change to Sandborn in the Card:
In short: Does anyone know a 'side road' that allows me to indirectly display the team name of the team that gets Rank1 value 1 at that moment, in a Card visual?

Dax measure that counts number of occurrence

I want to create measure Invoice Counter that shows number of invoices per customer. This measure must reflect slicer in the page.
If in year slicer is selected year = 2022, measure should reflex this.
Sorry I don't paste my test code here, it was nonsense so far.
Thanks for help.
Your modelling approach is a little awkward: Your table shows an Invoice Counter of 3 for the single invoice 11 in 2022 for "jack", and the sum of Invoice Counter is 14, although there are 6 different invoices only. This is at least confusing ...
Your Invoice counter measure should aggregate invoice like this:
Invoice Counter =
CALCULATE(
COUNT('Table'[invoice]),
ALLEXCEPT('Table', 'Table'[customer])
)
but then you can't filter it by invoice again, because that will undo the above aggregation. Just put customer, year and Invoice Counter in one table and of cause you can filter that table by year, if you like:

How to show the records which are part between selected date range in Dax

I have a below table in Power BI. This table will have the details of campaigns which are ran on specific period.
Campaign Name StartDate Enddate
AAA 01-05-2022 30-04-2022
BBB 01-04-2022 30-04-2022
CCC 01-04-2022 30-04-2022
DDD 01-04-2022 30-09-2022
EEE 01-03-2022 30-09-2022
FFF 01-03-2022 30-09-2022
Now i am using the start date in the slicer. so if i select date range of Apr-22 to Jun-22, table should display whatever campaigns which are active between the selected period. In this case, it should display all the values from the above table, because all the campaigns are between Apr-Jun. but in my case, last two rows are not displaying since the start date is in March but these campaigns are also active during the period of Apr-22 to Jun-22. is there a way we can create some measure to show the campaigns, even if start date before selected slicer date range but end date falls between the selected date range?
You can try smth like this. The measure should return 1 for “active” if a company name is in scope and total number of active in total. But it would be better to create a DateTable as Ozan Sen advise. Otherwise you can get a wrong output - a slicer will return max and min dates that you have in table not as slicer shows. For instance your slicer shows you the first date as 01 Jan, but in your facts the minimum is 3 Jan, so, this you will get as minDate. The problem can come if the endDate is 02 Jan, the measure will not count it, because the minDate=03 Jan. With a Date table you'll avoid this kind of problem. I didn't check the measure, so I'm not 100% sure it works.
VAR minDate =Min('table'[startDate])
VAR maxDate =Max('table'[startDate])
VAR noOfCompNames =
CALCULATE(
CountRows(table)
,OR(
AND('table'[startDate]>=minDate,'table'[startDate]<= maxDate)
,AND('table'[endDate]<=minDate,'table'[endDate]>=maxDate
)
)
RETURN
noOfCompNames

How to capture a measure result at certain date?

I have 3 measures(Measure1, Measure2 & Measure3) in my dataset. I have a "Sprint Begin" column in the dataset, what I wanted to do is calculate "Measure1" on every Sprint Begin date and capture that result. and calculate "Measure2" only after 7 days of Sprint Begin date, and calculate Measure3 only after 14 days of Sprint Begin date, each measure value should be captured for 14 days until the next Sprint Begin. I want to refresh each measure only every 14 days from the last refresh of each measure.
I want to calculate & refresh Measure1 when Max(Sprint begin)=today() only, else show the previous value( from last refresh)..Calculate and refresh measure2 when Max(Sprint begin)+7=today() only, else show the previous value( from last refresh)...calculate and refresh measure3 when Max(Sprint begin)+13=today() only, else show the previous value( from last refresh). those measures can be shown in a card visual.
Team Sprint Sprint Begin Sprint End
Team1 Sprint1 1/1/2021 1/15/2021
Team1 Sprint2 1/16/2021 1/30/2021
Team2 Sprint1 1/1/2021 1/15/2021
Team2 Sprint2 1/16/2021 1/30/2021
I was trying to store the measures in separate new tables using summarize(by Team & Sprint columns) and refresh them on those certain days manually but my source tables are big I could not even store them in separate tables because of memory issues. Any help?
you can create a master table for just storing the informations like
Sprint | Sprint Begin | spring end
this will help you to calculate in your measure by referring current date with the sprint begin and end date.

How to remove blank rows in a Power BI Table

I run monthly reports to show month over month impact on our transportation costs. I need to have a formula that will remove blank rows when there is not a record in the current period or previous period.
Routing Current Month Previous Month
aaaa 100 150
bbbb 125
cccc 200 210
dddd 180
My formula for trying to deal with this is:
MoM PPV =
IF(OR(ISBLANK([$/Container]), ISBLANK([PREVIOUS MONTH $CONTAINER])),
BLANK(),
DIVIDE([OCEAN CONTAINER DIFFERENCE], 'GCF Ocean'[$/Container])
)
EDITED
If your measure returns BLANK(), then power bi desktop automatically remove rows.
Measure = CALCULATE( DIVIDE(sum('Table'[Current]), sum('Table'[Previous])) )
example:
EDITED:
SumOfPrev = CALCULATE(SUM('Table'[Previous]))
SumOfCurrent = CALCULATE(SUM('Table'[Current]))
Measure = CALCULATE( DIVIDE([SumOfCurrent], [SumOfPrev]) )
You can try with visual level filter as shown in attached image. It will remove all the blank record which your measure "MoM PPV" code return.