简体   繁体   English

Tableau计算的字段日期

[英]Tableau calculated field dates

I was trying to do a calculated field and I cannot get it to work right. 我试图做一个计算字段,但无法使其正常工作。

First I tried to duplicate what I did in access... 首先,我试图复制我在访问中所做的工作...

    =DateDiff("d",[90 Days to Exp],[Expiration])        

but that gives me an error 但这给我一个错误

I did some research and found something that gave me valid calculations... 我做了一些研究,发现一些可以有效计算的东西。

    window_sum(datediff('day',
                lookup(min([90 Days to Exp]), 0),
                min([Expiration])))                     

that only shows 90 days which I already knew 只显示90天,我已经知道

I want to make sure it is doing a count down of days to "Expiration" so I changed it to... 我想确定它正在对“到期” 倒数几天,所以我将其更改为...

    window_sum(datediff('day',
                lookup(min(NOW()), 0),
                min([Expiration])))          

also tried.... 也尝试过...

    window_count(datediff('day',
                lookup(min(NOW()), 0),
                min([Expiration])))

still a valid calc but the numbers are way off.... I tried min and max with and without... and I still can't seem to get an accurate count down 仍然是有效的计算结果,但数字远不止于此。...我尝试使用和不使用min和max ...,但似乎仍无法准确计数

Step back. 退后。 Instead of giving us random pieces of code, explain what you're trying to achieve (what you expect as a result) and what your db looks like (for instance, what are the fields). 与其给我们随机的代码,不如解释您要达到的目标(结果是什么)以及数据库的外观(例如,字段是什么)。

I'll give a solution to what I think you're trying to achieve on what I think you have as database. 对于我认为您要实现的数据库目标,我将给出解决方案。

I believe you have a database that each entry is a product that have an expiration date ([Expiration]). 我相信您有一个数据库,其中的每个条目都是具有到期日期([Expiration])的产品。 What I think you're trying to achieve is to know how many days are left until expiration date. 我认为您要达到的目的是要知道截止日期还剩下多少天。

So, if you want to calculate this for each entry in your database, the formula should be: 因此,如果要为数据库中的每个条目计算此值,则公式应为:

DATEDIFF('day',NOW(),[Expiration])

It's very straight forward, you're calculating how many days there are between today and expiration date 这很简单,您正在计算今天和到期日期之间有多少天

I have no idea why you're using table calculations in your suggestions, but if this calculations should not be done for each entry (but rather for a collection of entries), then table calculations can be useful, but it's impossible to suggest anything if I don't understand precisely what you want 我不知道为什么要在建议中使用表格计算,但是如果不应该为每个条目(而是一组条目)进行这种计算,那么表格计算会很有用,但是如果我不明白你想要什么

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM