Lucene : Best way to store and query a datastructure - lucene

I have a product whose price vary with day of week and season (like hotel room).
So consider , i have a rate card (and I can attach multiple rate cards to a product)
RateCard fields are
DateTime startdate
DateTime enddate
int priority
double price
double mon_surcharge
double tue_surcharge
double wed_surcharge
double thur_surcharge
double fri_surcharge
double sat_surcharge
double sun_surcharge
So my question is - how can i find product with order : start and end date , with range of min-max prices and sort them by price
Any suggestions

In LuceneNET I'd recommend that you change the structure of the price data to mon_price, tue_price, etc rather then having daily surcharges that must be added to price.
If you go with a daily price field then doing a range search on that field (or fields) should work great.

Related

How to right click table to show values?

In a pivot table that plots values against a timeline it is possible to right-click the table, select "Show values as..." and have them appear as a percentage of a particular day.
I'm trying to recreate the same behaviour using DAX measures: I would like to have a measure that shows each day's price as a percentage of the first day of the year.
I've successfully created a measure that correctly identifies the first date of the year, i.e. the baseline:
FDate:=CALCULATE(FIRSTDATE(Prices[Date]),ALLEXCEPT('Calendar','Calendar'[Year]))
However, I can't figure out how to use this FDate to get that day's price (needed as the baseline for further calculations):
CALCULATE([Sum of Price], ALLEXCEPT('Calendar','Calendar'[Year]), FILTER('Prices', 'Prices'[Date]=[FDate])) returns each day's price, not the first date's.
CALCULATE([Sum of Price], FILTER(ALLEXCEPT('Calendar','Calendar'[Year]),'Calendar'[Date]=[FDate])) ignores the YEAR report filter and returns the price of the very first date in my calendar table and not the first date in the year I've filtered for.
Any pointer in the right direction would be greatly appreciated!
Thanks
Here's the solution:
VAR FirstDate = [FDate]
RETURN(
CALCULATE([Price],
FILTER(ALLEXCEPT('Calendar','Calendar'[Year]),'Calendar'[Date]=FirstDate))
)
Variables allow you to define measure in a certain filter context but to leave it unaffected by subsequent filter contexts - that at least is my layman's understanding.
More info here: https://www.sqlbi.com/articles/variables-in-dax/

SSAS - Movement between from and two dates

we have a very specific problem on calculating movement using two dates from and to in cube and details are as follows:
Product group, sub group and asset and liability are derived using client type, product type and closing balance being in credit or debit on a particular day.
Product group, sub group and asset/liability can be selected from a dimension which has a surrogate key that is stored in the fact table against the date key and account key.
Fact table is "account's daily snapshot" which has every day's data starting from the date account was opened till today and the granularity is DateKey and AccountKey.
Consider the scenario that on 15th Jan a particular account was categorised as "Asset" based on associated product type, client type and closing balance value but on the 31st because of the movements after 15th till 31st; it went into "Liability". Now consider that the user would like to see the movements between these two dates and selects "from" and "to" dates in the cube using two date hierarchies.
The "to" date hierarchy runs on a date hierarchy where as "from" date hierarchy is dependent on floating date dimension that does not have any relationship and used with linked member function to get the starting point to perform the sum on "to" date hierarchy.
Now when issuing the two dates 15th and 31st on the cube; behind the scene data from 15th till 31st comes in scope of the selection which has key for asset and liability attribute values.
So when the user choose to show dimension attributes Product group, sub group and asset/liability the cube shows values against attribute values "Asset" and "Liability" which is correct on two rows.
Users would like to see that the asset or liability should be from the "to" date only but should also be able to pass from date to get the sum of movement.
We are wondering if we can keep the closing balance from "to" date and show Product group, sub group and asset/liability dimension attributes using this closing balance and using "from" date just to calculate the sum of movements but not to have impact on Product group, sub group and asset/liability attribute values and subtract it from closing balance to get the desired result.
Any help will be greatly appreciated.

DAX model invoice running balance

I have a table with invoices and a table with payments. The Invoice table consists of invoice id, amount, invoice date, expiry date. The payment table consists of invoice id, amount, payment date. The invoice table have an active relationship with the date table on the expiry date column. The payment table have an active relationship with the invoice table on the invoice id columns.
I would like to be able to show the invoice balance on an arbitrary day. Ie if I filter the report or page on a particular date I'd like to see the acual balance on that day per invoice. Anyone know how to acomplish this without creating a new table and programmatically fill it with invoice balance per day entries?
Here you go:
InvoiceTotalAmount:=
CALCULATE(
SUM(Invoice[Amount])
,ALL(DimDate) // The active relationship between Invoice[ExpiryDate]
// and DimDate[Date] would cause this to only be valid
// on the expiry date - we don't want that.
)
PaymentTotalToDate:=
CALCULATE(
CALCULATE( // We'll manipulate the relationship in the inner
// CALCULATE() before modifying context based on it
SUM(Payment[Amount])
,USERELATIONSHIP(Payment[Date], DimDate[Date])
)
,FILTER( // Now that that we're looking at the right relationship to
// DimDate, we can alter the date range in context
ALL(DimDate)
,DimDate[Date] <= MAX(DimDate[Date])
// Here, we take all dates less than the latest date in
// context in the pivot table - current date if 1 date in
// context, else last of week, month, quarter, etc....
)
)
InvoiceBalanceToDate:=[InvoiceTotalAmount] - [PaymentTotalToDate]
If you're not utilizing that active relationship between Invoice[ExpiryDate] and DimDate[Date], I'd mark it as inactive and the relationship between Payment[Date] and DimDate[Date] as the active one. You could then dispense with the CALCULATE() and ALL() in [InvoiceTotalAmount] and the inner CALCULATE() in [PaymentTotalToDate].
My model diagram:
You probably want to create a measure in the date table that uses CALCULATETABLE function to calculate the remaining balance of an invoice on that day.
https://technet.microsoft.com/en-us/library/ee634760(v=sql.105).aspx

MDX - sum costs up to a given date

This is a slight modification of what I stumbled upon while searching the web:
Let's say I have a dimension PROJECTS which contains:
project_id - unique id
category - category of a cost
project_date - date of summing up the cost
My warehouse also has the dimension of TIME with date, and a dimension COSTS containing values of costs. Those three dimensions are connected by the measure group EXPENSES which has:
id_date
id_cost
id_project
I want to wirte an MDX query which would group the projects by their category, and sum up all the costs, but only those which do not exceed the date given in the project_date attribute of the dimension PROJECTS (each category has the same project_date, I know it's redundant but I can't change it..)
I'm not sure, but maybe something alongside this?
SELECT
[COSTS].[COST] ON 0,
[PROJECTS].[category] ON 1
FROM [CUBE]
WHERE
[PROJECTS].[project_date] < #project_date

RaveDb/Lucene - Price Range query not working when start range is zero

I am using RavenDb for our Product Catalog. When I click into a category, I see my 5 products in that category, where one of the products is listed at 0.00. If I adjust my price range facet, for example I bring down the max price and the min price stays at 0, the zero priced product no longer appears when it still falls within the range. This only happens when the min range is zero, any other time when the min is greater than zero, the query works exactly as expected. This is the query being executed in Raven.
{Category:(categories/1839) AND Price_Range:[Dx0 TO Dx139]}
Any ideas? Thanks!
Just a guess, but try querying by either [Dx0.0 TO Dx139.0] or [NULL TO Dx139.0]