Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Calculate ranks dynamically based on Slicer

Hi There,

 

Currently I'm attempting to calculate a starting value based on range of data ranked containing goods issues and goods receipts by date. The problem I have is that my measure isn't working with my date slicer.

This is my expression:

StartingStock =
SUM(zMaterialWarehouseStockMovementQueryPBI[QuantityReceipts])
-
CALCULATE(SUM(zMaterialWarehouseStockMovementQueryPBI[QuantityReceipts]);
zMaterialWarehouseStockMovementQueryPBI[StockMovementCategory]="Goods Receipts")
-
CALCULATE(SUM(zMaterialWarehouseSTockMovementQueryPBI[QuantityReceipts]);
zMaterialWarehouseStockMovementQueryPBI[StockMovementCategory]="Goods Issues")

Any ideas on how to solve this?

Thanks in Advance!

12 REPLIES 12
afzalphatan
Resolver I
Resolver I

Can you post sample data and expected result ... that will have more clarity

nickchobotar
Skilled Sharer
Skilled Sharer

@Anonymous

 

 

Please share your data model and meanwhile you can test this measure. Make sure you have a relationship between zMaterialWarehouseStockMovementQueryPBI table and Data table.

 

 

CALCULATE (
    SUM ( zMaterialWarehouseStockMovementQueryPBI[QuantityReceipts] ),
    FIRSTNONBLANK (
        'Date'[Date],
        CALCULATE (
            SUM ( Inventory[UnitsBalance] ),
            zMaterialWarehouseStockMovementQueryPBI[StockMovementCategory]= "Goods Receipts",
            zMaterialWarehouseStockMovementQueryPBI[StockMovementCategory] = "Goods Issues"
        )
    )
)

 

N -

 

Anonymous
Not applicable

My data model consists of a single table (HANA view), where I connect to using DirectQuery. I don't have a date table but simply a date column with posting dates.

@Anonymous

 

You are trying to do a time intelligence here and in Power BI / Tabular echo system you will need a data table for that. Basically, you have two options. Bring your data in not as DirectQuery but as an import and then create a data table in M or keep DirectQuery but create a data table in your SAP source.

 

N -

Anonymous
Not applicable

Well, there's a challenge. DirectQuery is a requirement, but DirectQuery doesn't support relationships between HANA views. I basically need two measures:

1: total until the maximum date, while ignoring minimum date

2: total until the minimum date, while ignoring anything above.

@Anonymous

 

At this point it will be best if you share with us some data samples with the end result.

 

N -

Anonymous
Not applicable

Hi @nickchobotar

Here's the sample .PBIX file: https://we.tl/bsdSlQ6G1P

Looking back at my question, there are two measures that I need to create.  First of all my report has a minimum and maximum date in a slicer.

 

1. A measure that sums all stock until the minimum slicer date

2. A measure that sums all stock until the maximum slicer date

 

as mentioned before, because I'm using DirectQuery on SAP HANA, the following actions are impossible:

 

- Create a date table;

- Create relationships between tables.

 

Thanks in advance

@Anonymous

 

Give this a try and see if it returns the right logic

MinStock = 
VAR MinDate = MIN(Table1[Date]) RETURN
CALCULATE(
    SUM(Table1[Stock Change]),
    DATESBETWEEN(Table1[Date], MIN(Table1[Date]), MinDate)

)

MaxStock = 
VAR MaxDate = MAX(Table1[Date]) RETURN
CALCULATE(
    SUM(Table1[Stock Change]),
    DATESBETWEEN(Table1[Date], MIN(Table1[Date]), MaxDate)

)

Nick -

Anonymous
Not applicable

Hi Nick,

The logic keeps applying the slicer to the variables if I change it.

@Anonymous

 

I was working off these requirements:

 

"

1. A measure that sums all stock until the minimum slicer date

2. A measure that sums all stock until the maximum slicer date

 

"

 

Any chance you could post a very brief 10 row max sampling data and show exact the end result too. This should eliminate all the other questions.

 

N-

v-xjiin-msft
Solution Sage
Solution Sage

Hi @Anonymous,

 

In your scenario, how did you specify this date slicer? Were you using a calendar table? Or it is just a date column from the table zMaterialWarehouseStockMovementQueryPBI? If you were using a calendar table, have you created a relationship between the two tables?

 

Please share us more detailed information about your issue like some sample data which can help us repro your issue or some screenshots about your report. 

 

Thanks,
Xi Jin.

Anonymous
Not applicable

I am simply using a data column from the HANA Live view. Since I'm using DirectQuery and am only allowed to connect to a single HANA view.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.