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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Syndicate_Admin
Administrator
Administrator

Problem validating a stock with a price list (for previous period)

Good afternoon, everybody!

This post comes from the previous one: https://community.powerbi.com/t5/Translated-Spanish-Desktop/Problema-con-el-modelo-de-datos-medidas-...

I have been able to solve the problems of the relationship between tables, managing to obtain the desired results:

1) Obtain a stock by instrument type based on a fact table (purchases and sales of instruments)

2) I have been able to relate the price list of these instruments (2nd fact table) to the movement table, via a table with a calendar dimension.

The drawback I currently have is at the calculation level in DAX: I am not being able to obtain the valuation for the previous period (i.e. stock to the previous period multiplied by the price of the previous period).

I'm based on what I could find on the following link: https://www.daxpatterns.com/cumulative-total-excel-2013/

Periods are monthly. The price list contains only one month-end closing price. Entries are daily but stock is monthly. I'm not needing to value a daily stock, since I don't have a daily price list.

Here are the steps I could create:

CotizacionActual:

=IF(HASONEVALUE(DimFCI[Number]);MAXX(CALCULATETABLE(TOPN(1; QuotesFCI; QuotesFCI[Date]); QuotesFCI;FILTER(ALL(DimCalendario);D imCalendario[PeriodoID]<=Max(DimCalendario[PeriodID]))); QuotesFCI[Quote]))

CotizacionAnterior:

=IF(HASONEVALUE(DimFCI[Number]);MAXX(CALCULATETABLE(CotizacionesFCI;FILTER(ALL(DimCalendario);D imCalendario[PeriodoID]<=Max(DimCalendario[PERIODID])-1)); QuotesFCI[Quote]))

TenenciaActual:

=CALCULATE(SUM(EntriesFCI[Quantity]);FILTER(ALL(DimCalendario);D imCalendario[PeriodoID]<=Max(DimCalendario[PeriodoID])))

TenenciaAnterior:

=CALCULATE(SUM(EntriesFCI[Quantity]);FILTER(ALL(DimCalendario);D imCalendario[PeriodoID]<=Max(DimCalendario[PeriodoID])-1))

Current Valuation:

=SUMX(VALUES(DimFCI[Number]); [CotizacionActual][TenenciaActual])

Previous Valuation:

=SUMX(VALUES(DimFCI[Number]); [CotizacionAnterior][TenenciaAnterior])

The Current Valuation measure works perfectly. But in ValuationAnterior, for some instruments it takes prices that do not correspond to the corresponding period. I've tried the following measure, but it doesn't bring possible values for the Minimum Valuation measure:

CotizaciónAnterior2:

=IF(HASONEVALUE(DimFCI[Number]);MAXX(CALCULATETABLE(TOPN(1; QuotesFCI; QuotesFCI[Date]); QuotesFCI;FILTER(ALL(DimCalendario);D imCalendario[PeriodoID]<=Max(DimCalendario[PeriodID]) -1)); QuotesFCI[Quote]))

I await your comments. If you need more information, I'm all ears.

PS: I'm working on excel, with Power Pivot.

1 REPLY 1
v-easonf-msft
Community Support
Community Support

Hi,@leandro_salas24 

Not clear what you want.Mere links and formulas will not make me understand your problem more clearly.

Can you compressed your  problem into a simple case?

Sample data and expected output would help tremendously.

 

 

Best Regards,
Community Support Team _ Eason

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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